How can an internet connection be tested without pinging some website? I mean, what if there is a connection but the site is down? Is there a check for a connection with the world?
ping. The ping command is the simplest and most often used command for doing basic connectivity testing. It sends out packets called echo requests and are packets that request a response.
Step 1: In the search bar type “cmd” (Command Prompt) and press enter. This would open the command prompt window. “netstat -a” shows all the currently active connections and the output display the protocol, source, and destination addresses along with the port numbers and the state of the connection.
Without ping
#!/bin/bash wget -q --spider http://google.com if [ $? -eq 0 ]; then echo "Online" else echo "Offline" fi
-q : Silence mode
--spider : don't get, just check page availability
$? : shell return code
0 : shell "All OK" code
Without wget
#!/bin/bash echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "Online" else echo "Offline" fi
Ping your default gateway:
#!/bin/bash ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ok || echo error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With