How to find that an IP address is a LAN IP or WAN IP?

生来就可爱ヽ(ⅴ<●) 提交于 2020-05-12 11:14:05

问题


How can I find that an IP address is a LAN IP address or WAN IP address? I am writing a C API in Windows.Thanks


回答1:


Private IP addresses are usually set from the private IP address spaces:

  • 10.0.0.0/8
  • 172.16.0.0/12
  • 192.168.0.0/16

If the interface's IP addresses falls into one of these spaces, you can assume it is a private IP. Otherwise, it is a public (WAN) IP.




回答2:


Most likely, what you want to determine is whether the address is a global address, or a private address. The wikipedia article lists the address blocks that are reserved for private use.




回答3:


LAN vs WAN is meaningless in TCP/IP. There are only netmasks. If you can define what you mean by a LAN in terms of an IP netmask, the problem is trivial: does the IP address and the netmask give a non-zero result. If you can't define that, there is no solution.



来源:https://stackoverflow.com/questions/10311501/how-to-find-that-an-ip-address-is-a-lan-ip-or-wan-ip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!