Search code examples
cnetwork-programmingiplanwan

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


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


Solution

  • 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.