how to determine whether an IP address in private?

后端 未结 5 1916
不知归路
不知归路 2020-12-09 02:30

So far I have this code:

NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();

foreach (NetworkInterface adapter in adapters)
{
  IPInte         


        
5条回答
  •  情话喂你
    2020-12-09 03:22

    The private address ranges are defined in RFC1918. They are:

    • 10.0.0.0 - 10.255.255.255 (10/8 prefix)
    • 172.16.0.0 - 172.31.255.255 (172.16/12 prefix)
    • 192.168.0.0 - 192.168.255.255 (192.168/16 prefix)

    You might also want to filter out link-local addresses (169.254/16) as defined in RFC3927.

提交回复
热议问题