I see a lot of friends in the forum looking for this thing. I couldn't find it when I needed it some time ago. So I wrote this. There are still many bugs to fix and improve, but basically it works. Now I'm sending it out to those who need it.
****************** Code Segment ********************
@Title IP Gateway Automatic Switcher By Hanhe & Color 0a&&Mode CON Cols=45 Lines=15 &&Echo OFF
If Exist config.ini Del config.ini
@Echo The program will be automatically deleted after execution!>config.ini&Ipconfig|Find "IP Address">>config.ini&&Ipconfig|Find "Default Gateway" >>config.ini&&Ipconfig/all|Find "Ethernet adapter">>config.ini
::::::::::::::::: Define detailed variables :::::::::::::::::
Set First=192.168
Set Scend1=1
Set Scend2=0
Set Mask=255.255.255.0
Set Gate1=192.168.1.200
Set Gate2=192.168.0.200
::::::::::::::::: Get the local IP address information :::::::::::::::::
For /f "SkIp=2 Tokens=13" %%d in (config.ini) do Set Gate=%%d
For /f "SkIp=1 Tokens=15" %%c in (config.ini) do Set Ip=%%c
For /f "SkIp=3 Tokens=3,4 Delims=: " %%a in (config.ini) do Set Name=%%a %%b
@Echo %Ip% >>config.ini
For /f "SkIp=4 Tokens=4 Delims=./ " %%f in (config.ini) do Set Shree=%%f
@Echo ⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙
@Echo ⊙The current network information of your machine is as follows: ⊙
@Echo ⊙Connection name: %Name% ⊙
@Echo ⊙Used IP: %Ip% ⊙
@Echo ⊙Used gateway: %Gate% ⊙
@Echo ⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙
::::::::::::::::: Judge the network segment where the local machine is located :::::::::::::::::
IF /i "%Gate%"=="192.168.1.200" (Goto A_INTERNAME) Else (IF /i "%Gate%"=="192.168.0.200" (Goto B_INTERNAME))
::::::::::::::::: Processing for segment 1 :::::::::::::::::
:A_INTERNAME
@Echo.
@Echo Processing, please be patient...
Netsh interface Ip Set address "%Name%" static %First%.%Scend2%.%Shree% %Mask% %Gate2% 1
@Cls
@Echo Your gateway has been successfully switched. Current gateway (0).
For /f "SkIp=7 Tokens=15" %%k in ('Ipconfig') do Echo The modified network information of you is as follows: %%k
For /f "SkIp=9 Tokens=13" %%g in ('Ipconfig') do Echo The modified network information of you is as follows: %%g
Del config.ini
@Echo.
@Echo The line has been successfully switched. Press any key to exit the program.
@pause>nul
@exit
::::::::::::::::: Processing for segment 0 :::::::::::::::::
:B_INTERNAME
@Echo Processing, please be patient...
Netsh interface Ip Set address "%Name%" static %First%.%Scend1%.%Shree% %Mask% %Gate1% 1
@Cls
@Echo Your gateway has been successfully switched. Current gateway (1).
For /f "SkIp=7 Tokens=15" %%k in ('Ipconfig') do Echo The modified network information of you is as follows: %%k
For /f "SkIp=9 Tokens=13" %%g in ('Ipconfig') do Echo The modified network information of you is as follows: %%g
Del config.ini
@Echo.
@Echo The line has been successfully switched. Press any key to exit the program.
@pause>nul
@exit
********************* End *********************
The code is not encrypted. Friends who need it can modify it themselves. I wrote this just for my own convenience.
I didn't consider the convenience for the public..
I'll improve it if I have the opportunity in the future..
[ Last edited by newaifi on 2007-2-16 at 10:50 PM ]
****************** Code Segment ********************
@Title IP Gateway Automatic Switcher By Hanhe & Color 0a&&Mode CON Cols=45 Lines=15 &&Echo OFF
If Exist config.ini Del config.ini
@Echo The program will be automatically deleted after execution!>config.ini&Ipconfig|Find "IP Address">>config.ini&&Ipconfig|Find "Default Gateway" >>config.ini&&Ipconfig/all|Find "Ethernet adapter">>config.ini
::::::::::::::::: Define detailed variables :::::::::::::::::
Set First=192.168
Set Scend1=1
Set Scend2=0
Set Mask=255.255.255.0
Set Gate1=192.168.1.200
Set Gate2=192.168.0.200
::::::::::::::::: Get the local IP address information :::::::::::::::::
For /f "SkIp=2 Tokens=13" %%d in (config.ini) do Set Gate=%%d
For /f "SkIp=1 Tokens=15" %%c in (config.ini) do Set Ip=%%c
For /f "SkIp=3 Tokens=3,4 Delims=: " %%a in (config.ini) do Set Name=%%a %%b
@Echo %Ip% >>config.ini
For /f "SkIp=4 Tokens=4 Delims=./ " %%f in (config.ini) do Set Shree=%%f
@Echo ⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙
@Echo ⊙The current network information of your machine is as follows: ⊙
@Echo ⊙Connection name: %Name% ⊙
@Echo ⊙Used IP: %Ip% ⊙
@Echo ⊙Used gateway: %Gate% ⊙
@Echo ⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙⊙
::::::::::::::::: Judge the network segment where the local machine is located :::::::::::::::::
IF /i "%Gate%"=="192.168.1.200" (Goto A_INTERNAME) Else (IF /i "%Gate%"=="192.168.0.200" (Goto B_INTERNAME))
::::::::::::::::: Processing for segment 1 :::::::::::::::::
:A_INTERNAME
@Echo.
@Echo Processing, please be patient...
Netsh interface Ip Set address "%Name%" static %First%.%Scend2%.%Shree% %Mask% %Gate2% 1
@Cls
@Echo Your gateway has been successfully switched. Current gateway (0).
For /f "SkIp=7 Tokens=15" %%k in ('Ipconfig') do Echo The modified network information of you is as follows: %%k
For /f "SkIp=9 Tokens=13" %%g in ('Ipconfig') do Echo The modified network information of you is as follows: %%g
Del config.ini
@Echo.
@Echo The line has been successfully switched. Press any key to exit the program.
@pause>nul
@exit
::::::::::::::::: Processing for segment 0 :::::::::::::::::
:B_INTERNAME
@Echo Processing, please be patient...
Netsh interface Ip Set address "%Name%" static %First%.%Scend1%.%Shree% %Mask% %Gate1% 1
@Cls
@Echo Your gateway has been successfully switched. Current gateway (1).
For /f "SkIp=7 Tokens=15" %%k in ('Ipconfig') do Echo The modified network information of you is as follows: %%k
For /f "SkIp=9 Tokens=13" %%g in ('Ipconfig') do Echo The modified network information of you is as follows: %%g
Del config.ini
@Echo.
@Echo The line has been successfully switched. Press any key to exit the program.
@pause>nul
@exit
********************* End *********************
The code is not encrypted. Friends who need it can modify it themselves. I wrote this just for my own convenience.
I didn't consider the convenience for the public..
I'll improve it if I have the opportunity in the future..
[ Last edited by newaifi on 2007-2-16 at 10:50 PM ]
