1

I'm trying to build bat file for my uncle who needs once click solution to change ip as I advised him not to fidget with fragile modem power button. How can I achieve also some option will be attractive.

I tried this but didn't work.

ipconfig/release
[some 1 min interval]
ipconfig/renew

For a wifi modem we were not able to achieve such thing, we had to switch it off and on manually

Shiva
  • 717
  • 9
  • 22

3 Answers3

1

On Windows 7 and later it's pretty simple:

ipconfig /release 
timeout 60 
ipconfig /renew

Earlier systems:

ipconfig /release
ping -n 60 localhost > nul
ipconfig /renew

I got the ping/sleep hack from this answer.

Community
  • 1
  • 1
xsl
  • 17,116
  • 18
  • 71
  • 112
  • thanks xsl he uses Win 7 hope timeout will do the job... but I'm trying to build it as a generic tool so I can give it to others so will choose later :) – Shiva Nov 05 '13 at 10:21
  • Also that the reason I choose .bat against .cmd; since .bat works for 16-bit, I read this somewhere not sure about it have to test it on 16-bit :D if I get one – Shiva Nov 05 '13 at 10:22
  • `ping -n 60 localhost >nul` <-- this is a more straightforward ping delay for nearly 60 seconds. – foxidrive Nov 05 '13 at 11:14
  • this works but I'm hunting on other possible solutions, reason is that simply clicking a bat file must not change ip that won't be cool. what if someone presses it by mistake – Shiva Nov 05 '13 at 13:18
1

Update 11/11/13: the question is still open. ipconfig was not strong enough to fix it... still you can make use of choice options incase you are building a tool for anyother purpose. Choice command won't work in Win XP and Win 2000 replace them by set command and accordingly goto statements too

xsl help is appreciated but after much googling I found ping 1.1.1.1 is not cool instead we have to use ping 127.0.0.0, here is what I have done. And here is where I found the choice commands details http://www.torgersens.net/wordpress/?p=273 long before Rock cud answer just that I was fine tuning my answer.

@echo off
:Menu
echo.
echo C for Change IP  or Q to Quit
echo.
:Choice
choice /C CQ /M "Enter Choice"
goto ERR%errorlevel%
:ERR1
ipconfig /release 
ping localhost -n 10 -w 1000 > nul
ipconfig /renew
echo Done
goto END
:ERR2
echo Bye
goto END
:END
pause
Shiva
  • 717
  • 9
  • 22
0

Adding to what xsl has answered.

@echo off
choice /C YN /M "Are you sure you want to change your ip?" 
ipconfig /release 
timeout 60 
ipconfig /renew

You can add timeout to the choice.

Rock
  • 11
  • 3
  • I use a similar approach and found the answer, your answer is not complete – Shiva Nov 05 '13 at 15:04
  • sadly I have answer but not able to post it now... your implementation of choice won't work as you are not verifying any condition. http://www.torgersens.net/wordpress/?p=273 here this helped me – Shiva Nov 05 '13 at 15:19