-3

I am currently working on a project where I need to check if a computer visiting my webpage is connected to a specific network. My first idea was to compare the clients external IP with the current IP of the reference network, but obviously I would need to run a program on this network which checks the router's IP for changes. I thought about setting up a javascript/jquery code which searches on the client side for the local router and then (don't know yet how exactly) compares it to the router of the reference network.

Does anyone have an idea about an elegant solution for that? Doesn't matter if client- or server-side code.

Rex Cramer
  • 11
  • 2

2 Answers2

1

I think squint's comment highlights a point about your design. You should reconsider what it actually is that you need to do. Does the client need to access a local network resource? Then you could use Javascript to check if the network resource is available by pinging the LAN IP or trying to get an HTTP response. How you would do this depends heavily on the resource your dealing with.
But let's back up another step, if the problem your trying to solve is something like a resource that's only available on a particular network, then the easiest thing to do is only allowing users to access the page in question once they're on the network, i.e. unless they're on the Wifi that you need them to be on they get a 404 error.
Beyond the need to access a local network resource, I can't think of any reasons to check the SSID of the connected Wifi network. You should rethink your problem, what it actually is that your trying to get the user to accomplish, and then restate your question.

Edit
Here's link to a more specific question about getting a client's local IP. Seems that HTML5 has some facilities for doing so through WebRTC.

Community
  • 1
  • 1
phip
  • 577
  • 5
  • 12
  • Thank you for your answer! So, to be more specific about the problem itself: I am working on a little webpage which is supposed to save working times for employees. A worker should be able to log in and start or stop a clock running for the time he has been working. Now, before starting the clock, my webpage should check if the computer, the employee is using (can be Laptop or even mobile devices) is connected to the Wifi of the working place, and if not prevent the starting of the clock. – Rex Cramer Dec 20 '15 at 23:11
  • Put the webpage on a local server, so they can only access the page when they're connected to the local network. – phip Jan 09 '16 at 01:08
0

With Javascript I don't think you can parse for the local network of the client. It would be a security hole.

But if you know the external IP of the network, you can just compare to the client IP.

If your web server is on the network, it should be quite trival to compare the external server IP and the external client IP with PHP.

Lambic
  • 145
  • 6