0

我希望编写一个批处理文件,该文件采用当前的 IP/子网/网关/DNS 并对其进行静态设置(XP 及更高版本)。即使它已经是静态的,我在网上找到了一个脚本,但我需要找到当前 IP 信息的部分。如果适配器总是被命名为“本地连接”我会很好,但不是。任何人都可以帮忙吗?

@ECHO OFF

set varip=
set varsm=
set vargw=
set vardns1=
set vardns2=
set varhome=

ECHO Setting IP Address and Subnet Mask
netsh int ip set address name = "Local Area Connection" source = static addr = %varip% mask = %varsm%

ECHO Setting Gateway
netsh int ip set address name = "Local Area Connection" gateway = %vargw% gwmetric = 1

ECHO Setting Primary DNS
netsh int ip set dns name = "Local Area Connection" source = static addr = %vardns1%

ECHO Setting Secondary DNS
netsh int ip add dns name = "Local Area Connection" addr = %vardns2%

rem ECHO Here are the new settings for %computername%:
rem netsh int ip show config

pause

谢谢,

埃里克

4

1 回答 1

0
@ECHO OFF

ipconfig /all | findstr Ethernet | findstr IP Address | find str ( the first digit of your ip normally " 1 " ) > IP.txt

ipconfig /all | findstr Ethernet | findstr Subnet | find str ( the first digit of your subnet normally " 2 " ) > SUBNET.txt

ipconfig /all | findstr Ethernet | findstr Primary DNS | find str ( the first digit of your dns normally " 1 " ) > dns1.txt

ipconfig /all | findstr Ethernet | findstr Secondary DNS | find str ( the first digit of your dns normally " 1 " ) > .txt

 ipconfig /all | findstr Ethernet | findstr Default Gateway | find str ( the first digit of your gateway normally " 1 " ) > gateway.txt

 ipconfig /all | findstr Ethernet | findstr ISP | find str ( the first digit of your ISP normally " 1 " ) > home.txt



set ip=for /f "delims= " in ( IP.txt ) do ( set varip=IP.txt )
set sm=for /f "delims= " in ( SUBNET.txt ) do ( set varip=SUBNET.txt )
set gw=for /f "delims= " in ( gateway.txt ) do ( set varip=gateway.txt )
set dns1=for /f "delims= " in ( dns1.txt ) do ( set varip=dns1.txt )
set dns2=for /f "delims= " in ( dns2.txt ) do ( set varip=dns2.txt )
set home=for /f "delims= " in ( home.txt ) do ( set varip=home.txt )

ECHO Setting IP Address and Subnet Mask
netsh int ip set address name = "Local Area Connection" source = static addr = %varip%  mask     = %varsm%

ECHO Setting Gateway
netsh int ip set address name = "Local Area Connection" gateway = %vargw% gwmetric = 1

ECHO Setting Primary DNS
netsh int ip set dns name = "Local Area Connection" source = static addr = %vardns1%

ECHO Setting Secondary DNS
netsh int ip add dns name = "Local Area Connection" addr = %vardns2%

pause
于 2013-05-14T04:22:04.313 回答