China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-09 20:02
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Seeking a batch processing approach to modify the gateway based on the computer name? Thanks View 1,754 Replies 11
Original Poster Posted 2008-09-23 07:48 ·  中国 江苏 苏州 昆山市 电信
新手上路
Credits 14
Posts 6
Joined 2008-09-23 06:53
17-year member
UID 126364
Gender Male
Status Offline
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
Floor 2 Posted 2008-09-23 09:07 ·  中国 上海 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
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.
Floor 3 Posted 2008-09-23 09:42 ·  中国 广西 南宁 电信
初级用户
Credits 115
Posts 45
Joined 2007-03-03 10:09
19-year member
UID 80655
Gender Male
Status Offline
To read the computer name, you can directly run hostname.exe
Floor 4 Posted 2008-09-23 09:46 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
```
@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?
Floor 5 Posted 2008-09-23 10:28 ·  中国 江苏 苏州 昆山市 电信
新手上路
Credits 14
Posts 6
Joined 2008-09-23 06:53
17-year member
UID 126364
Gender Male
Status Offline
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.
Floor 6 Posted 2008-09-23 10:30 ·  中国 江苏 苏州 昆山市 电信
新手上路
Credits 14
Posts 6
Joined 2008-09-23 06:53
17-year member
UID 126364
Gender Male
Status Offline
Please take a look, thank you.
Floor 7 Posted 2008-09-23 10:40 ·  中国 江苏 苏州 昆山市 电信
新手上路
Credits 14
Posts 6
Joined 2008-09-23 06:53
17-year member
UID 126364
Gender Male
Status Offline
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.
Floor 8 Posted 2008-09-23 10:41 ·  中国 江苏 苏州 昆山市 电信
新手上路
Credits 14
Posts 6
Joined 2008-09-23 06:53
17-year member
UID 126364
Gender Male
Status Offline
In addition, the default is 1.252, and numbers 1-13 can remain unchanged
Floor 9 Posted 2008-09-23 10:56 ·  中国 广西 南宁 电信
初级用户
Credits 115
Posts 45
Joined 2007-03-03 10:09
19-year member
UID 80655
Gender Male
Status Offline
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 ]
Floor 10 Posted 2008-09-23 11:00 ·  中国 江苏 苏州 昆山市 电信
新手上路
Credits 14
Posts 6
Joined 2008-09-23 06:53
17-year member
UID 126364
Gender Male
Status Offline
Thanks, I'll try it and see.
Floor 11 Posted 2008-09-23 11:01 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
```
@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
)
)
```
Floor 12 Posted 2008-09-23 11:26 ·  中国 广西 南宁 电信
初级用户
Credits 115
Posts 45
Joined 2007-03-03 10:09
19-year member
UID 80655
Gender Male
Status Offline
@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 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
everest79 +5 2008-09-23 14:12
Forum Jump: