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

电信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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值