Windows'for'脚本

时间:2012-05-09 15:18:05

标签: windows batch-file

我正在寻找一个批处理文件,该文件采用当前的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

谢谢,

埃里克

1 个答案:

答案 0 :(得分: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
相关问题