Static IP on LAN question

Started by
5 comments, last by kordova 17 years, 7 months ago
Hey, quick question. I have a small function to detect if a given IP address is located on a LAN, but I ran into a small issue: At my university, numerous computers are on a LAN, but have a static IP address (visible to the world). Is there another way, other than maybe using pings to detect if this type of computer is also on a local LAN? -I could also use broadcasting, I suppose. Effort... EDIT: your average LAN addresses are 192.168.xxx.xxx, but these are 129.xxx.xxx.xxx, and are visible via broadcasting.
Advertisement
Virtually all computers are "on a LAN", that is, connected directly to a layer-2 switching device instead of a layer-3 bridge. Also, the definition of a "static IP address" has nothing to do with whether the IP address is "visible to the world". You seem to be confusing several concepts here. What is it you're actually trying to do?
-Basically, I'm using lots of computers on a Lan.
-They have an internet IP, not a LAN IP (192.168 etc etc)
-They can talk to each other via broadcast

-What I'm asking is, in this situation, is there a direct way of detecting if these computers are connected on a "layer 2" switch, as you call it (I'm not an expert)
Sure. All you need is your IP, their IP, and your netmask. If YOUR_IP & YOUR_NETMASK == THEIR_IP & YOUR_NETMASK, you're connected on the same LAN.

Example: Your IP is 129.128.159.51. Your netmask is 255.255.0.0. Their IP is 129.128.188.22. AND-ing the netmask to the IP addresses results in 129.128.0.0 (also known as your network address) and 129.128.0.0. They're the same, so you're connected.

Example: Your IP is 129.128.159.51. Your netmask is 255.0.0.0. Their IP is 136.44.14.183. AND-ing the netmask to the IP addresses results in 129.0.0.0 and 136.0.0.0. They're different, so you're not on the same LAN.
Awesome! Thanks! I didn't think of that because I'm still a networking noob.
oops, one more question: How do I retrieve the netmask for a given socket/address?
Assuming that you are using Windows: Winsock Example.

This topic is closed to new replies.

Advertisement