0

I have a laptop I bring with me between work and home. I would like to make it so when connected to the wireless network at work, it uses certain settings (there are weird proxies there) and when at home it uses other settings (custom DNS for unblockus that will likely muck up any internal things).

I have read into using locations in the Networking preferences, but it seems they do not do what I need, and would need to be manually switched.

Is there a way that networking rules can automatically change based on which wireless network I am connected to?

Damon
  • 2,789
  • 6
  • 28
  • 29

1 Answers1

0

You can run a tiny script after you connect to the other network. First, create a this batch script:

ping -n 1 some.local.ip.addy
if errorlevel 1 goto :isremote1
cp /Y %WINDIR%\System32\Drivers\etc\hosts.local %WINDIR%\System32\Drivers\etc\hosts
goto :eof
:isremote1
ping -n 1 some.remote1.ip.addy
if errorlevel 1 goto :isremote2
cp /Y %WINDIR%\System32\Drivers\etc\hosts.remote1 %WINDIR%\System32\Drivers\etc\hosts
goto :eof
:isremote2
ping -n 1 some.remote2.ip.addy
if errorlevel 1 goto :isunknownnet
cp /Y %WINDIR%\System32\Drivers\etc\hosts.remote2 %WINDIR%\System32\Drivers\etc\hosts
goto :eof
:isunknownnet
cp /Y %WINDIR%\System32\Drivers\etc\hosts.public %WINDIR%\System32\Drivers\etc\hosts
goto :eof
Add as many more networks as you like to this file...

Change, some.XXXX.ip.addy to an actual IP on each network. Make sure that it is something which is always available (the router IP would do nicely as long as it responds to a PING request).

Then create a hosts file (%WINDIR%\System32\Drivers\etc\hosts.XXX) for each network and put whatever you need into it.

192.168.0.2 my-service.mynet.dyndns.org
192.168.0.3 my-service2.mynet.dyndns.org

After you have this working, you can make it automatic using the task manager.

krowe
  • 5,629