# Problem with dynamic IP-need a batchfile



## dhiraj05 (Aug 29, 2009)

My ISP provides me an internet connection with dynamic IP. when i need to change my ip i simply disconnect my dial-up connection using a bat file (rasdial "dial-up connection name" /disconnect) and reconnect with same bat file using command rasdial "dial-up connection name" username password. It mostly works but sometime it is annoying to find afterward while browsing that my IP has not changed. It happens say once in every 10 to 15 attempts. Can there be a bat file which on execution notes current Ip address then disconnects internet then reconnects and then verifies whether Ip address has changed or not and if IP address has not changed it goes back to disconnect and reconnect until IP address changes.


----------



## Squashman (Apr 4, 2003)

_Posted via Mobile Device_
Anything is possible. I have a batch file at work that copies my ip address to the clipboard. you would have to store you old ip in a text file before disconnecting first.
Why do you need your ip address to change?


----------



## Squashman (Apr 4, 2003)

Here is the code I use to get my IP address in a batch file. All you would need to do is write it out to a text file before disconnecting and then read that file into a variable after reconnecting to see if the IP changed. This may need to be tweaked for your particular computer.

```
:: Note: the following code will extract only the last IP address from the list
FOR /F "TOKENS=2* DELIMS=:" %%A IN ('IPCONFIG /ALL ^| FIND "IP Address"') DO FOR %%B IN (%%A) DO SET IPADDR=%%B
```


----------



## OlderAdmin (Sep 2, 2009)

Try these commands to release and renew your IP address after you change connection types.

ipconfig /release
ipconfig /renew
ipconfig /all

pause


----------

