本帖最后由 小智BAT 于 2014-10-14 06:47 编辑
大家帮忙测试下,如有建议都提出来。
代码已经更新这个看,看看有还有什么问题??- @echo off
- title IP自动改手动批处理。
- color 0a
- ver | find "5.1." > NUL && goto show51
- ver | find "6.1." > NUL && goto show61
- :show51
- @echo 当前系统是:[WindowsXP ]
-
- echo ------------------------
- echo 正在获取本地连接地址信息:
- set "w1=wmic nic where "NetConnectionID='本地连接'" get Index"
- for /f %%a in ('%w1% ^| findstr /b [0-9]') do set "n=%%a"
- set "w2=wmic nicconfig where "Index='%n%'" get DNSServerSearchOrder^,DefaultIPGateway^,IPAddress^,IPSubnet"
- for /f tokens^=1-2delims^={^" %%a in ('%w2% /value^|find "."')do set "%%a%%b"
- echo ============================
- echo,IP地址:%IPAddress%
- echo,子网:%IPSubnet%
- echo,网关:%DefaultIPGateway%
- echo,DNS:%DNSServerSearchOrder%
- echo 正在修改为手动IP地址
- netsh interface ip set address name="本地连接" source=static addr=%IPAddress% mask=%IPSubnet%
- netsh interface ip set address name="本地连接" gateway=%DefaultIPGateway% gwmetric=0
- echo 正在修改DNS为:%DNSServerSearchOrder%和114.114.114.114
- netsh interface ip set dns name="本地连接" source=static addr=%dns%
- netsh interface ip add dns name="本地连接" addr=114.114.114.114
- pause & exit
- :show61
- @echo 当前系统是:[Windows7 ]
- echo ------------------------
- echo 正在获取本地连接地址信息:
- set "w1=wmic nic where "NetConnectionID='本地连接'" get Index"
- for /f %%a in ('%w1% ^| findstr /b [0-9]') do set "n=%%a"
- set "w2=wmic nicconfig where "Index='%n%'" get DNSServerSearchOrder^,DefaultIPGateway^,IPAddress^,IPSubnet"
- for /f tokens^=1-2delims^={^" %%a in ('%w2% /value^|find "."')do set "%%a%%b"
- echo ============================
- echo,IP地址:%IPAddress%
- echo,子网:%IPSubnet%
- echo,网关:%DefaultIPGateway%
- echo,DNS:%DNSServerSearchOrder%
- echo ============================
- goto workdo
- :workdo
- set "pattern_包含=^[^.]*\.[^.]*\.[^.]*\.[^.]*$"
- set "pattern_排除=[^.][^.][^.][^.] [^0-9.] \.\."
- echo %IPAddress%|findstr "%pattern_包含%"|findstr /v "%pattern_排除%"|findstr /v "[0-9][0-9][0-9][0-9] [3-9][0-9][0-9] 2[6][0-9] 25[6-9]" && goto workip || echo 本地连
-
- 接网络没连接或者网线没拆好。&goto exitip
- :workip
- echo 正在修改为手动IP地址:%IPAddress% %IPSubnet% %DefaultIPGateway% %DNSServerSearchOrder%
- netsh interface ip set address name="本地连接" source=static addr=%IPAddress% mask=%IPSubnet% gateway=%DefaultIPGateway% gwmetric=1
- echo 正在修改DNS为:114.114.114.114和%DNSServerSearchOrder%
- netsh interface ipv4 set dns name="本地连接" source=static addr=%DNSServerSearchOrder%
- netsh interface ipv4 add dns name="本地连接" addr=114.114.114.114
- echo 修复完成。
- pause & exit
-
- :exitip
- exit
- pause
复制代码
|