![]() |
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-09 20:55 |
47,811 topics / 349,897 posts / today 2 new / 48,255 members |
| DOS批处理 & 脚本技术(批处理室) » Seeking a batch processing approach to modify the gateway based on the computer name? Thanks |
| Printable Version 1,756 / 11 |
| Floor1 bingobe | Posted 2008-09-23 07:48 |
| 新手上路 Posts 6 Credits 14 | |
|
As the title says, there are currently 39 computers, with computer names from 1 to 39, no prefixes or suffixes, just single digits. The gateways are 192.168.1.252---254, a total of 3, one gateway per 13 units. Since it's diskless, it's more troublesome to set the gateways respectively. I want to ask experts to help make a batch script to automatically modify the gateway according to the computer name.
Thanks, urgent. I just wrote two lines, can't go on. ipconfig /all >ip.txt for /f "delims=" %%a in ('findstr "Host Name" ipconfig.txt') do echo %%a>>NAME.txt Extracted the line with the computer name, still want to extract the computer name alone, and then use the computer name to arrange. If it's less than how many, use how many gateways. Always can't get it right. Finally, I want to use the IF command plus the following line to realize automatic gateway switching netsh interface ip set address name="Local Area Connection" source=static gateway=*.*.*.* gwmetric=1 Thanks |
|
| Floor2 dato | Posted 2008-09-23 09:07 |
| 高级用户 Posts 377 Credits 916 | |
|
You can take a look at this post.
Everyone can help improve the scanning of LAN MAC addresses and converting them to modiip. http://www.cn-dos.net/forum/viewthread.php?tid=42427&fpage=1&highlight=%2Bdato What I am doing now is that the master disk obtains the IP via DHCP. After ghosting is complete, first allocate the IP via DHCP, then use psexec to execute modiip to automatically set the IP. Modiip is very good for automatically modifying the IP. |
|
| Floor3 ceii | Posted 2008-09-23 09:42 |
| 初级用户 Posts 45 Credits 115 | |
|
To read the computer name, you can directly run hostname.exe
|
|
| Floor4 HAT | Posted 2008-09-23 09:46 |
| 版主 Posts 5,017 Credits 9,023 | |
|
```
@echo off for /f "tokens=16 delims= " %%a in ('ipconfig /all^|findstr /c:"Host Name"') do ( if %%a leq 13 ( echo Computer name 1-13 ) else if %%a leq 26 ( echo Computer name 14-26 ) else ( echo Computer name 27-39 ) ) ``` Can you handle automatically switching gateways by yourself? |
|
| Floor5 bingobe | Posted 2008-09-23 10:28 |
| 新手上路 Posts 6 Credits 14 | |
|
Here I'm using BXP for diskless. I can handle disked ones, but just started with diskless. The problem is that BXP diskless can only use one gateway. I mean, after entering the system, automatically execute the boot batch, modify the gateway according to the machine number, without manual intervention. Can the elder above also write the subsequent steps? Thanks a million.
|
|
| Floor6 bingobe | Posted 2008-09-23 10:30 |
| 新手上路 Posts 6 Credits 14 | |
|
Please take a look, thank you.
|
|
| Floor7 bingobe | Posted 2008-09-23 10:40 |
| 新手上路 Posts 6 Credits 14 | |
|
It would be best if some elder brother can make a full - version one. After entering the system, scan your computer name, then change the gateway according to the name. Machines 1 - 13 use 1.252, 14 - 26 use 1.253, and 27 - 39 use 1.254. Thank you all great experts, save me, Amen.
|
|
| Floor8 bingobe | Posted 2008-09-23 10:41 |
| 新手上路 Posts 6 Credits 14 | |
|
In addition, the default is 1.252, and numbers 1-13 can remain unchanged
|
|
| Floor9 ceii | Posted 2008-09-23 10:56 |
| 初级用户 Posts 45 Credits 115 | |
|
Run hostname.exe and assign the result to aaa
set wangguan=252 if aaa>=14 set wangguan=253 if aaa>=27 set wangguan=254 finally add %wangguan% to the netsh command [ Last edited by ceii on 2008-9-23 at 11:15 AM ] |
|
| Floor10 bingobe | Posted 2008-09-23 11:00 |
| 新手上路 Posts 6 Credits 14 | |
|
Thanks, I'll try it and see.
|
|
| Floor11 HAT | Posted 2008-09-23 11:01 |
| 版主 Posts 5,017 Credits 9,023 | |
|
```
@echo off for /f "tokens=16 delims= " %%a in ('ipconfig /all^|findstr /c:"Host Name"') do ( if %%a leq 13 ( netsh interface ip set address name="Local Area Connection" source=static gateway=192.168.1.252 gwmetric=1 ) else if %%a leq 26 ( netsh interface ip set address name="Local Area Connection" source=static gateway=192.168.1.253 gwmetric=1 ) else ( netsh interface ip set address name="Local Area Connection" source=static gateway=192.168.1.254 gwmetric=1 ) ) ``` |
|
| Floor12 ceii | Posted 2008-09-23 11:26 |
| 初级用户 Posts 45 Credits 115 | |
|
@echo off
for /f %%i in ('hostname') do set a=%%i set w=252 if %a% gtr 13 set w=253 if %a% gtr 26 set w=254 echo netsh i i s a "本地连接" s gateway=192.168.1.%w% gwmetric=1 [ Last edited by ceii on 2008-9-23 at 11:38 AM ] |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |