Detecting network Connectivity I'm using the Cong approach, which is " External Network -- Gateway -- Intranet -- This machine " , the implementation of the script is also based on this order Ping to detect, in order to improve the detection speed, here I only Ping the 2 times, you can make changes according to your own needs.
How to use the great gods will ... copy code, save as . Bat after the file is executed.
1 @echo off2 Color 2F3 Title Network connectivity detection4 Echo.5 ifExist%temp%\*.PingDel%temp%\*.Ping:: Delete Cache6 Echo.7 Ping-N2223.5.5.5>>%temp%\1.Ping&Ping-N2223.6.6.6>>%temp%\1.Ping::p ing ali public DNS address8Findstr"TTL"%temp%\1.Ping>nul9 if%errorlevel%==0(Echo√ External network normal)Else(Echox Outside Network):: Return value output according to commandTen Echo. One Ping-N2192.168.1.1>>%temp%\2.Ping AFindstr"TTL"%temp%\2.Ping>nul - if%errorlevel%==0(Echo√ Gateway Normal)Else(Echox Gateway not through) - Echo. the Ping-N2192.168.1.2>>%temp%\3.Ping -Findstr"TTL"%temp%\3.Ping>nul - if%errorlevel%==0(Echo√ Normal intranet)Else(Echox Intranet not through) - Echo. + Ping-N2127.0.0.1>>%temp%\4.Ping -Findstr"TTL"%temp%\4.Ping>nul + if%errorlevel%==0(Echo√TCP/IP protocol OK)Else(Echoxtcp/IP Protocol Exception) A Echo. at Echo. -Pause
The effect is as follows:
Windows Batch: Automatically check network connectivity