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
Asked
Active
Viewed 5,834 times
-1
-
2"LAN" vs. "WAN" depends on the environment. If you're on a corporate network, what do you consider LAN: your local network segment? The building network? Campus/site network? Entire corporate network? – geekosaur Apr 25 '12 at 07:54
-
2@Sarfraz, there has got to be a better way to determine the connection potential than to use IP address heuristics. Latency and error rate seem like better candidates. – jedwards Apr 25 '12 at 08:23
-
@geekosaur TO ALL: I've found this but i dont understand a thing its saying! http://en.wikipedia.org/wiki/List_of_assigned_/8_IPv4_address_blocks - how on earth can one determine the list of non-WAN (non-internet facing) IP addresses? IE: If we owned www.whatismyipaddress.com, and we logged all IP's that came there, what are the list of IP addresses that we can be guaranteed that we'd never, ever see due to the layout of the IPv4 spec. – Erx_VB.NExT.Coder Sep 08 '12 at 22:07
-
@Erx_VB.NExT.Coder, go to the source, the _[IANA IPv4 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml)_, where you can see if a special purpose address is global, can be used as a source or destination address, is forwardable (can be routed), etc. Add multicast (`224.0.0.0/4`) to the list of non-routable, non-public addresses, and you are done. The rest are routable on the public Internet. Of course, that does not mean that public addresses cannot be used on a LAN, as many large companies do. – Ron Maupin Apr 22 '20 at 15:09
3 Answers
5
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.

Martin v. Löwis
- 124,830
- 17
- 198
- 235
-
my purpose is that how to determine that a given IP is LAN IP address, WAN IP address or Intranet IP Address. Thanks – Sarfraz Ahmed Apr 25 '12 at 07:53
-
1That is not a meaningful question. My computer has only a single IP address, which it uses both on the LAN and in the internet. Why do you think that "LAN IP addresses" are different from "WAN IP addresses"? They are not, except that you may use private addresses on the LAN, see my answer. – Martin v. Löwis Apr 25 '12 at 09:05
-
No, I'm sorry RFC 1918 private IP addresses are used on corporate WANs all the time. The correct heuristic for this problem is as mentioned in a comment above, error rate and latency – Mike Pennington Apr 25 '12 at 09:11
-
@MikePennington We need all the other non-wan addresses as well, like 127.0.0.1, the low 100.64.0.0+10 address space, the 224.0.0.n address space, the 0.0.0.0, the subnet mask 255.255.255.0 and all the other non internet (non wan) ip addresses that i cannot think of at the moment, if one could help gather a list, we can create a proper function that will test an IP address to confirm if it is a legit WAN IP (internet facing) address or not, anyone willing to help? – Erx_VB.NExT.Coder Sep 08 '12 at 21:57
-
@Martinv.Löwis We need all the other non-wan addresses as well, like 127.0.0.1, the low 100.64.0.0+10 address space, the 224.0.0.n address space, the 0.0.0.0, the subnet mask 255.255.255.0 and all the other non internet (non wan) ip addresses that i cannot think of at the moment, if one could help gather a list, we can create a proper function that will test an IP address to confirm if it is a legit WAN IP (internet facing) address or not, anyone willing to help?? – Erx_VB.NExT.Coder Sep 08 '12 at 21:58
0
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.

Aziz
- 20,065
- 8
- 63
- 69
-
-
-
@Sarfraz We need all the other non-wan addresses as well, like 127.0.0.1, the low 100.64.0.0+10 address space, the 224.0.0.n address space, the 0.0.0.0, the subnet mask 255.255.255.0 and all the other non internet (non wan) ip addresses that i cannot think of at the moment, if one could help gather a list, we can create a proper function that will test an IP address to confirm if it is a legit WAN IP (internet facing) address or not, anyone willing to help? – Erx_VB.NExT.Coder Sep 08 '12 at 21:56
-
Public addresses can be, and often are in large companies with blocks of public addresses, used on a LAN. IP has no distinction between public and private addresses. The private addressing was arbitrarily chosen, and the ISPs agree not to send packets with those addresses on the public Internet, but IP itself has no concept of public or private. – Ron Maupin Apr 22 '20 at 15:04
-
@RonMaupin You are right. My answer also assumes that "LAN" refers to a private network behind a NAT (Network Address Translation) router. – Aziz Apr 22 '20 at 15:23
0
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.

user207421
- 305,947
- 44
- 307
- 483
-
We need all the other non-wan addresses as well, like 127.0.0.1, the low 100.64.0.0+10 address space, the 224.0.0.n address space, the 0.0.0.0, the subnet mask 255.255.255.0 and all the other non internet (non wan) ip addresses that i cannot think of at the moment, if one could help gather a list, we can create a proper function that will test an IP address to confirm if it is a legit WAN IP (internet facing) address or not, anyone willing to help??? If so, post here, im watching. – Erx_VB.NExT.Coder Sep 08 '12 at 21:58