|
bingobe
新手上路

积分 14
发帖 6
注册 2008-9-23
状态 离线
|
『楼 主』:
求根据计算机名称修改网关的批处理做法?谢谢
使用 LLM 解释/回答一下
如题现有39台电脑,计算机名称分别是1-39,没有前后缀,单数字
网关有192.168.1.252---254,共3个,每13台一个网关
由于是无盘,分别设置网关比较麻烦,想请高手帮忙做个批处理,根据计算机名来自动修改网关
谢谢了,急
我就写了两条,写不下去了,
ipconfig /all >ip.txt
for /f "delims=" %%a in ('findstr "Host Name" ipconfig.txt') do echo %%a>>NAME.txt
把计算机名那行提取出来了,还想把计算机名单独提出来,然后以计算机名来排不足多少的用多少网关,老搞不好,
最后想用IF命令加后面这条来实现自动切换网关
netsh interface ip set address name="本地连接" source=static gateway=*.*.*.* gwmetric=1
谢谢了
Last edited by bingobe on 2008-9-23 at 07:54 AM ]
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
|
|
2008-9-23 07:48 |
|
|
dato
高级用户
   
积分 916
发帖 377
注册 2004-3-8
状态 离线
|
|
2008-9-23 09:07 |
|
|
ceii
初级用户
 
积分 115
发帖 45
注册 2007-3-3
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
读取计算机名可以直接运行 hostname.exe
To read the computer name, you can directly run hostname.exe
|
|
2008-9-23 09:42 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
@echo off
for /f "tokens=16 delims= " %%a in ('ipconfig /all^|findstr /c:"Host Name"') do (
if %%a leq 13 (
echo 计算机名称1-13
) else if %%a leq 26 (
echo 计算机名称14-26
) else (
echo 计算机名称27-39
)
)
自动切换网关自己能搞定不?
```
@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?
|

 |
|
2008-9-23 09:46 |
|
|
bingobe
新手上路

积分 14
发帖 6
注册 2008-9-23
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
我这里是无盘 用的BXP 有盘我可以搞定 无盘才接触的
问题是BXP无盘只能用一个网关
我的意思是进系统后自动执行开机批处理,根据机器号来修改网关,不需要人工干预
楼上的大哥能不能把后面的步骤也写一下呢?
感激不尽
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.
|
|
2008-9-23 10:28 |
|
|
bingobe
新手上路

积分 14
发帖 6
注册 2008-9-23
状态 离线
|
|
2008-9-23 10:30 |
|
|
bingobe
新手上路

积分 14
发帖 6
注册 2008-9-23
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
最好哪位大哥能帮我做个完整版的出来就好了
进系统后扫描自己计算机名,然后根据名字改网关
1-13号机器用1.252
14-26用1.253
27-39用1.254
谢谢各位高手同志了,救救我吧,阿门
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.
|
|
2008-9-23 10:40 |
|
|
bingobe
新手上路

积分 14
发帖 6
注册 2008-9-23
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
另外,默认的是1.252,1-13号可以不改
In addition, the default is 1.252, and numbers 1-13 can remain unchanged
|
|
2008-9-23 10:41 |
|
|
ceii
初级用户
 
积分 115
发帖 45
注册 2007-3-3
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
运行 hostname.exe 并将结果赋值到 aaa
set wangguan=252
如果 aaa>=14 set wangguan=253
如果 aaa>=27 set wangguan=254
最后将 %wangguan% 加到 netsh 命令中
Last edited by ceii on 2008-9-23 at 11:15 AM ]
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 ]
|
|
2008-9-23 10:56 |
|
|
bingobe
新手上路

积分 14
发帖 6
注册 2008-9-23
状态 离线
|
|
2008-9-23 11:00 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
@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="本地连接" source=static gateway=192.168.1.252 gwmetric=1
) else if %%a leq 26 (
netsh interface ip set address name="本地连接" source=static gateway=192.168.1.253 gwmetric=1
) else (
netsh interface ip set address name="本地连接" source=static gateway=192.168.1.254 gwmetric=1
)
)
```
@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
)
)
```
|

 |
|
2008-9-23 11:01 |
|
|
ceii
初级用户
 
积分 115
发帖 45
注册 2007-3-3
状态 离线
|
 『第 12 楼』:
使用 LLM 解释/回答一下
@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 ]
@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 ]
|
|
2008-9-23 11:26 |
|