determine if 2 IP's are on the same subnet?

  • Thread starter Thread starter JamesB
  • Start date Start date
J

JamesB

I'm looking for a function to return true/false depending on if two supplied
IP's (as strings) are in the same subnet (also supplied).
Im getting nowhere fast unfortunately - I know the theory behind it, but I
have no idea on how to actually implement it!
I have split my supplied 3 IP's into 4 numbers each, but past that I'm
stuck - on paper I would convert them to binary and write down all the 1's
and 0's then figure it out, but in code...?
Thanks
James
 
You need to use the "and" function between each of the 4 octects in the ip
and the equilavalent octect in the net mask to get the "network" address.
If the network address is the same for the two ip's then they are the same
network.

Hope this helps..

Regards
Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top