Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Programming Talk / Java / JSP - How do I determine if a computer is on my local network or not?

Author
Message
Mr Z
18
Years of Service
User Offline
Joined: 27th Oct 2007
Location:
Posted: 8th Oct 2009 17:18 Edited at: 8th Oct 2009 17:18
Hi all.

I would like to add a setting in the server program I am making in Java, so that only people that is on my local network can connect. However, I am not sure how to do this. Anyone know how to check if a socket comes from the local network or from the "outside"?

Take care,
Mr Z

"Operator! Give me the number for 911!"
- Homer J. Simpson
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 8th Oct 2009 17:47
Well, if you're behind a router and there isn't port forwarding set up for this particular protocol/port, it shouldn't happen.

Otherwise you could check if the address falls into one of these ranges: http://en.wikipedia.org/wiki/Private_network#Reserved_private_IPv4_address_space.
Mr Z
18
Years of Service
User Offline
Joined: 27th Oct 2007
Location:
Posted: 8th Oct 2009 19:33
I know, but I still would like the option to be there. At the moment all I check is if the three first parts of the IP address is the same, but that is not the same thing as a LAN... or is it?

"Operator! Give me the number for 911!"
- Homer J. Simpson
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 8th Oct 2009 21:27
Most of the time on a home LAN the addresses will fall into one of those ranges. It may be possible to set it up differently but I doubt this is done in domestic environments.
NeX the Fairly Fast Ferret
21
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 8th Oct 2009 22:19
Not a good way of doing it. IP spoofing.

Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 8th Oct 2009 23:27
You can't actually initiate a connection via spoofing (nor can you intercept packets if you're outside of the local network), so this isn't really an issue.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Oct 2009 21:11
Check the connecting PC's IP and see if it fits into the subnet the network is using.

Mr Z
18
Years of Service
User Offline
Joined: 27th Oct 2007
Location:
Posted: 12th Oct 2009 10:46
Sorry for the late reply.

Quote: "Most of the time on a home LAN the addresses will fall into one of those ranges. It may be possible to set it up differently but I doubt this is done in domestic environments."

Yeah, I know. But my university happen to be one of those places that has it setup differently, lol.

Quote: "Check the connecting PC's IP and see if it fits into the subnet the network is using."

How do I do that in Java?

"Operator! Give me the number for 911!"
- Homer J. Simpson
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Oct 2009 04:52
ipconfig will give you the subnet your on, so run that from whichever computer you're running the server on and configure a variable with it.

And connection with your server program will know what the IP of the client is, sorta how TCP works. The socket class should have the methods needed, check the API docs.

Mr Z
18
Years of Service
User Offline
Joined: 27th Oct 2007
Location:
Posted: 17th Oct 2009 18:52
Quote: "ipconfig will give you the subnet your on, so run that from whichever computer you're running the server on and configure a variable with it."

Not even sure how to do that, lol. I do not know very much about subnets. Are you saying I could check the subnet of the incoming connection to make sure it is on the same one as I am?

Quote: "And connection with your server program will know what the IP of the client is, sorta how TCP works. The socket class should have the methods needed, check the API docs."

Have checked there, and I know how to get the correct IP. But do not know how to use that to see if they are on the same local network as I am.

"Operator! Give me the number for 911!"
- Homer J. Simpson

Login to post a reply

Server time is: 2026-06-10 03:29:52
Your offset time is: 2026-06-10 03:29:52