试试我这个
从192.168.0.3到192.168.0.255逐个IP去PING,如果PING不通的,那说明那个IP还没被占用,那就把PING不通的IP设置为运行该批处理电脑的IP地址,这样在局域网里不用逐台电脑去改IP地址,自动设置,
- @echo off
- setlocal EnableDelayedExpansion
- for /l %%i in (3,1,255) do (
- set "aa=%%i"
- ping/n 1 192.168.0.%%i >nul
- if !ERRORLEVEL! equ 1 goto szip
- )
- goto :eof
-
- :szip
- set slection1=
- set slection1=192.168.0.!aa!
- echo 现在要设置的IP是 %slection1%
- PAUSE
- cls
- netsh interface ip set address name="本地连接" source=static addr=%slection1% mask=255.255.255.0
- netsh interface ip set address name="本地连接" gateway=192.168.0.1 gwmetric=0
- netsh interface ip set dns name="本地连接" source=static addr=202.102.152.3 register=PRIMARY
- netsh interface ip add dns name="本地连接" addr=202.102.154.3
- netsh interface ip set wins name="本地连接" source=static addr=none
复制代码
|