问题
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