现在的位置: 首页 > 综合 > 正文

批处理检测网络连通禁用启用网卡重启电脑

2013年10月27日 ⁄ 综合 ⁄ 共 1044字 ⁄ 字号 评论关闭

电信dhcp服务器好像强制超过48小时客户端必须重新获取新IP,故写此批处理,在计划任务里设置每5分钟执行一次

通过PING 8.8.8.8和218.244.180.1这两个IP测试网络连通性,如果两个都ping不通则禁用启用对外网卡,如果连续8次都不能ping通,则重启服务器

@echo off
rem 测试服务器的连通性,如果不能ping通8.8.8.8和218.244.180.1则重起网卡
set trynum=0
set mydate=%date:~0,10%
set mydelay=6
:START
ping -n 3 218.244.180.1>nul
if %errorlevel% equ 1 goto TRYMORE
set t=%time:~0,8%
echo %t% success in %trynum% ping 218.244.180.1>>neterror%mydate%.txt
exit

:TRYMORE
set t=%time:~0,8%
echo %t% error in %trynum% ping 218.244.180.1>>neterror%mydate%.txt
ping -n 3 8.8.8.8>nul
if %errorlevel% equ 1 goto RBNET
set t=%time:~0,8%
echo %t% success in %trynum% ping 8.8.8.8>>neterror%mydate%.txt
exit

:RBNET
set t=%time:~0,8%
echo %t% error in %trynum% ping 8.8.8.8>>neterror%mydate%.txt
if %trynum% equ 8 goto REBOOT
if %trynum% equ 9 goto REBOOT
netsh interface set interface name = "internet" admin=DISABLED
choice /t %mydelay% /d y >nul
netsh interface set interface name = "internet" admin=ENABLE
echo %t% reboot network in %trynum% >>neterror%mydate%.txt
set /a trynum=%trynum%+1
set /a mydelay=%mydelay%+6
goto START
exit

:REBOOT
set t=%time:~0,8%
echo reboot computer at %t% >>neterror%mydate%.txt
shutdown -r -f -t 40
exit

 

抱歉!评论已关闭.