Batch Files - Using ping to test network connectivity

前端 未结 8 1116
名媛妹妹
名媛妹妹 2021-01-04 17:17

Using a batch file would it be possible to do something like:

ping google.com

if return success do ECHO You are connected to the internet

else return

8条回答
  •  清歌不尽
    2021-01-04 17:54

    Based on the answer from @CShulz, here's a script that'll print "Not connected" only when there's no connection, else it'll silently loop through the test every 30 seconds. First ping tests for connectivity & prints an error message if there's a problem. The second ping adds a 30 second wait by pinging the localhost.

    @echo off
    :loop
    ping www.google.com -n 1 -w 5000 > nul
    if errorlevel 1 echo Not connected
    ping -n 30 127.0.0.1 > nul
    goto loop
    

提交回复
热议问题