Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
Why do you need to change your IP anyway? Sounds dodgy to me :P –  Thorarin Aug 29 '09 at 13:33
add comment

migrated from stackoverflow.com Aug 29 '09 at 14:32

This question came from our site for professional and enthusiast programmers.

7 Answers

Something like this should work

ipconfig | find "IP Address" > tempip.txt
set /p tvar=< tempip.txt

:untilloop

do redial here

ipconfig | find "IP Address" > tempip.txt
set /p newip=< tempip.txt
if %tvar%==%newip% goto untilloop
share|improve this answer
add comment

If you need to do so in a bat, you could use a for loop with the output of ipconfig in your set block. Grab your initial IP address out before you disconnect, and test it using the same process once you reconnect.

I am not sure why you would 'need' to change your IP address. I would be interested in understanding the reasons, as they aren't as obvious as you indicate they should be in your comment.

share|improve this answer
    
Thanks akf, I am using a simple single bat file to connect and disconnect net. Which is as follows: @echo off rasdial "dial-up connection name" /disconnect rasdial "dial-up connection name" username password Please change it as you suggested and let me no here because I know nothing about batch or any programming and so I can not do it myself. As for as reason behing the whole thing is concerned, I want to download files from rapidshare etc without much hassle as a free user. Regards –  Dhiraj Aug 29 '09 at 14:19
add comment

Have you contacted your ISP support?

  • Find out what the DHCP lease times are.
  • Ask them what factors might cause your IP address to change. I woudln't mention that you are trying to get a different one.

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.

You might need to wait a significant portion of the lease time to renew, although if you get a different address 90+% of the time, maybe not.

I've generally been more concerned with preserving the address, so I'm not sure what you should do to avoid that. Nonetheless, these might be informative:

share|improve this answer
add comment

If you can change your MAC address each time you run the script, you will certainly receive a new IP from DHCP server. Chances of MAC conflicts are pretty low.

share|improve this answer
add comment

Hmmm. How to Beat Rapidshare Download Limits and Waiting Time?


In response to the down vote on this answer...
If I recollect correctly, the OP had described his reasons for changing IP address to bypass the RapidShare locking...

share|improve this answer
add comment

It often happens that if you connect too fast, then you get the same IP address.

On my ISP, for example, a delay of at least 15 minutes is required for a new IP, but may take longer.

share|improve this answer
add comment

If you have many network cards than the ipconfig method may not be good. Also you can eliminate the temporary file wit following logic:

for /f "tokens=3" %%i in (
   'netsh interface ip show addresses "Connection Name"^| findstr "IP"'
) do set ip=%%i

:dountill
rasdial "dial-up connection name" /disconnect
rasdial "dial-up connection name" username password

for /f "tokens=3" %%i in (
   'netsh interface ip show addresses "Connection Name"^| findstr "IP"'
) do set ipnew=%%i

:delay a sec or so
PING 1.1.1.1 -n 1 -w 2 >NUL
if %ip%==%newip% goto dountill
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.