|
Question : Netsh - script to check DHCP enabled
|
|
How can I create a script that does something like this...
If computer has dynamic ip then run netsh interface ip set dns "Local Area Connection" dhcp
else if computer has a static ip, assign dns of 10.0.0.3 as prefered dns..
Does this make sense? How would I put this into a batch or vbs file?
Please refer to question - http://www.experts-exchange.com/Networking/Q_21326923.html
CODE should be something like?
IF IP = DHCP:Enabled netsh interface ip set dns "Local Area Connection" dhcp ELSE RUN netsh interface ip set dns "Local Area Connection" static 10.0.0.3
Thanks
|
Answer : Netsh - script to check DHCP enabled
|
|
Very little change to use that netsh command. (I'm a little paranoid I'm missing something here...)
for /f "tokens=3" %%a in ('netsh interface ip show config ^| find /i "DHCP Enabled"') do set DHCP=%%a If /i "%dhcp%" == "Yes" ( netsh interface ip set dns "Local Area Connection" dhcp ) Else ( netsh interface ip set dns "Local Area Connection" static 10.0.0.3 )
You could actually avoid the environment variable entirely with this:
for /f "tokens=3" %%a in ('netsh interface ip show config ^| find /i "DHCP Enabled"') do ( If /i "%%a" == "Yes" ( netsh interface ip set dns "Local Area Connection" dhcp ) Else ( netsh interface ip set dns "Local Area Connection" static 10.0.0.3 ) )
|
|
|