“以太网” 为网卡名称,“E:/iptest/iplist.txt”里存放需要ping的ip地址,每行一个
@echo off :main echo ================ echo 1:网络设置 echo 2:自动获取IP echo 3:Ping Ip地址 echo 4:初始化网路设置 echo 5:结束 echo ================ set /p choice=你的选择: echo. if "%choice%"=="1" goto initSet if "%choice%"=="2" goto dhcpIp if "%choice%"=="3" goto pingIp if "%choice%"=="4" goto dhcpSet if "%choice%"=="5" goto end :initSet echo IP自动设置开始.... echo. echo 正在设置IP及子网掩码 cmd /c netsh interface ip set address name="以太网" source=static addr=172.168.1.101 mask=255.255.255.0 gateway=172.168.1.1 gwmetric=1 echo 正在设置DNS服务器 cmd /c netsh interface ip set dns name="以太网" source=static addr=192.168.1.1 register=PRIMARY echo 正在设置DNS服务器 cmd /c netsh interface ip add dns name="以太网" addr=172.168.1.1 set err=%errorlevel% if "%err%"=="0" ( echo 设置成功 goto main ) else if "%err%"=="1" ( echo 设置失败 goto main ) else ( echo 错误码:%errorlevel% goto main ) :dhcpIp echo IP自动设置开始.... echo. echo 自动获取IP地址.... netsh interface ip set address name = "以太网" source = dhcp echo 自动获取DNS服务器.... netsh interface ip set dns name = "以太网" source = dhcp [@rem](https://my.oschina.net/u/196541) 设置自动获取IP set err=%errorlevel% if "%err%"=="0" ( echo 设置成功 goto main ) else if "%err%"=="1" ( echo 设置失败 goto main ) else ( echo 错误码:%errorlevel% goto main ) :pingIp echo ping 网路地址开始.... ::获取时间 set date=%date:~0,4%-%date:~5,2%-%date:~8,2%%time:~0,8% ::读取iplist进行ping操作 for /f %%a in (E:/iptest/iplist.txt) do ( echo IP地址:%%a echo %date%begin_ping %%a: >>checkout.txt ::执行5次ping且剔除过程 ping %%a -n 5 |find ")" >>checkout.txt echo %date%end_ping %%a >>checkout.txt ) echo ping 网路地结束.... :dhcpSet netsh interface ip set address name = "以太网" source = dhcp netsh interface ip set dns name = "以太网" source = dhcp netsh interface ip set wins name = "以太网" source = dhcp set err=%errorlevel% if "%err%"=="0" ( echo 设置成功 goto main ) else if "%err%"=="1" ( echo 设置失败 goto main ) else ( echo 错误码:%errorlevel% goto main ) :end pause exit