View Single Post
  #5  
Old 18.10.2010, 10:01
drbits's Avatar
drbits drbits is offline
JD English Support (inactive)
 
Join Date: Sep 2009
Location: Physically in Los Angeles, CA, USA
Posts: 4,437
Default Batch script for no router, multiple IPs

This has to be run as an administrator. Netsh is slow, so all enough time in the reconnection timeout (30 seconds is plenty).

This also serves as an example for rotating through multiple proxies, NICs, MAC addresses, or other lists

The list of values can also be stored in an environment variable instead of files. In that approach, if the variable is empty or missing, it is set up with a string of space separated values. If %1 is empty, call the script recursively with the expanded variable as a parameter. Now %1 is like %V below. Before exiting, use SHIFT to remove %1 from the variable and then reassign the variable with %*.

Code:
setlocal

REM Replace the next line with the correct directory.
    cd /d c:\programs\jdownloader
REM Change DSL below to the name of your connection (shown by ipconfig.exe).
REM    Mine shows "Ethernet Adapter: DSL"
    set adapter=DSL
REM Change 255.255.255.0 below to the subnet mask shown by ipconfig.exe
    set mask=255.255.255.0

if not exist iplist\* mkdir iplist
cd iplist
if not exist *.ip (
REM Change the following to your IP addresses.
    echo "not used yet" > 192.168.1.15.ip
    echo "not used yet" > 192.168.1.16.ip
)

for %%V in (*.ip) do (
    echo %%~nV
    set NewIP=%%~nV
    goto :have_IP
)
:have_IP
    del %NewIP%.ip
    REM Be patient, the next line is very slow.
    netsh interface ip set address %adapter% static %NewIP% %mask%
endlocal
drbits

Last edited by drbits; 18.10.2010 at 10:07.
Reply With Quote