javascriptnetwork-programmingbrowserhttp-redirect

How do I use JavaScript to detect the name of the network my computer is connected to?


I want to write some JavaScript that is able to detect/read the name of the network I am connected to; for example, when I move between two different wireless networks with different SSIDs. Preferably a for loop or a case/switch so that depending on the name of the network, I am able to redirect my browser accordingly.

Thank you.


Solution

  • The comments to your question are correct. JavaScript code, like any other code is bound by the constraints of the environment it runs within. There are two potential answers...

    The most likely answer is that you are trying to do the described logic within a browser. If that is the case, then you're dependant on the environment the browser gives you. And no browsers that I know of give you access to machine resources like the network adapter. This would be a security hole in the browser. Therefore you can't determine the SSID from javascript running within a browser. A better question you could pose, might be "how do I redirect traffic to another server based on the wireless network you're currently connected to"...

    The other answer is that you're running the javascript code in a standalone interpreter. If that interpretter gives you access to the network resources, then you can determine the SSID... after that you could possible muck with the host file to redirect network traffic. However, I expect this is not what you're attempting to do.