![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-03 14:03 |
48,038 topics / 350,123 posts / today 0 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » 【Original】:Gateway Automatic Switcher. |
| Printable Version 1,644 / 3 |
| Floor1 newaifi | Posted 2007-02-16 02:27 |
| 初级用户 Posts 67 Credits 154 | |
|
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 ] |
|
| Floor2 windows9x | Posted 2007-02-16 06:15 |
| 初级用户 Posts 10 Credits 24 | |
|
I don't know what the use of such a long piece of code is... I tried it, and I only know that it switches gateways like 192.168. But if it's another gateway, it simply doesn't switch. This is called automatic? It's not as convenient as changing it manually.
|
|
| Floor3 newaifi | Posted 2007-02-16 22:56 |
| 初级用户 Posts 67 Credits 154 | |
|
I have already said. Writing this is just for my own convenience. I didn't consider the needs of the public. Those who need it can take it and modify it.
As for why it can only modify the 192.168 segment, I think anyone with a little common sense should understand. Some things are completely impossible to achieve automatically. Even if it can recognize your IP, the program may not know which segment you want to modify, and it can't know how many segments you have. So I used the ::::::: symbol above this thing to declare it as a variable, and users need to modify it themselves. If you want to enjoy the fruits without effort, you won't learn anything.. |
|
| Floor4 voiL | Posted 2007-02-24 16:51 |
| 中级用户 Posts 189 Credits 384 | |
Originally posted by windows9x at 2007-2-16 06:15: This can first obtain the current network segment... save it... Then change the network segment... Finally, when it needs to be restored, just take out the previously saved network segment and restore it. Isn't that okay... |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |