How to find that an IP address is a LAN IP or WAN IP?
-
03-06-2021 - |
Frage
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
Lösung
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.
Andere Tipps
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.
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.