-2

for a server, i want to determine whether two clients is in the same LAN.

the clients may show me there local ips. such as 192.168.x.x . they are both LAN ip. they don't have public ip.

is there any identifier for a LAN?

saintthor
  • 41
  • 7

1 Answers1

0

You need the network mask to determine if IP addresses are in the same network.

The way to determine if two addresses are in the same network is to mask (logical AND) the addresses with a network mask. For example:

Address 10.11.12.13   -> 00001010000010110000110000001101
Mask    255.255.192.0 -> 11111111111111111100000000000000
                     AND ================================
Network               -> 00001010000010110000000000000000 -> 10.11.0.0
Ron Maupin
  • 6,180
  • 4
  • 29
  • 36
  • the two hosts are in LANs, only have local ip, do not have public ip. most hosts in LAN have not public ip. they access internet by NAT. – saintthor May 23 '17 at 02:01
  • IP addressing is the exact same for _any_ unicast IP addressing. The only difference between private and public IP addresses is that the ISPs have agreed to not route traffic with destination IP addresses defined by RFC 1918, which were chosen in a purely arbitrary manner. Subnetting is exactly the same way for both public and private IP addresses. – Ron Maupin May 23 '17 at 02:07
  • for example, i set a wifi network at home. my computer has the ip 192.168.0.1, my phone has 192.168.0.2. my neighbours, 10000000 familys have such wifi too. all of us send the same ip 192.168.0.x to the server. can the server determine which and which is in the same family by mask? – saintthor May 24 '17 at 02:58
  • So what? Those are IP addresses, and IP addressing is IP addressing, regardless if it is public or private. The private IP address ranges were chosen arbitrarily, and the only difference between public and private ranges is that the ISPs have agreed not to forward packet with destination addresses in the private ranges. My answer holds true for both public and private address ranges. In fact, my example is using private addressing, but it can be applied to public addressing, too. – Ron Maupin May 24 '17 at 03:02