How to check if an IP address is within a particular subnet

后端 未结 7 1436
深忆病人
深忆病人 2020-12-01 12:15

I have a subnet in the format 10.132.0.0/20 and an IP address from the ASP.Net request object.

Is there a .NET framework function to check to see if the IP address i

相关标签:
7条回答
  • 2020-12-01 12:42

    I'm late to the party here, but had a similar need, and put together a quick package to do exactly this.

    https://www.nuget.org/packages/IpMatcher/

    and source:

    https://github.com/jchristn/IpMatcher

    Simple use:

    using IpMatcher;
    
    Matcher matcher = new Matcher();
    matcher.Add("192.168.1.0", "255.255.255.0");
    matcher.Add("192.168.2.0", "255.255.255.0");
    matcher.Remove("192.168.2.0");
    matcher.Exists("192.168.1.0", "255.255.255.0");  // true
    matcher.Match("192.168.1.34"); // true
    matcher.Match("10.10.10.10");  // false
    
    0 讨论(0)
提交回复
热议问题