jeudi 26 novembre 2015

Create batch script to change network settings by current network connection

I want to use a batch script which:

  • changes my network settings to a static ip when I'm at home
  • changes my network settings to dhcp when I'm not at home

I read here that you can check the network name by using

for /f "tokens=3" %%a in ('netsh wlan show interface ^| findstr /r "^....SSID"' ) do @echo %%a

So if I want to create a batch script like that would it look something like this?

for /f "tokens=3" %%a in ('netsh wlan show interface ^| findstr /r "My_Cool_Home_Network"' ) do ( if "%%a"=="My_Cool_Home_Network" netsh interface ip set address "NetworkAdapter" static 192.168.2.33 255.255.255.0 192.168.2.1 netsh interface ip set dns "NetworkAdapter" static 192.168.2.1 else netsh interface ip set address "NetworkAdapter" dhcp netsh interface ip set dns "NetworkAdapter" dhcp )

Aucun commentaire:

Enregistrer un commentaire