Skip to content

Instantly share code, notes, and snippets.

@vertexvaar
Created May 6, 2022 06:54
Show Gist options
  • Save vertexvaar/b3e64ba0201dcdd56bf90a9a2c68e533 to your computer and use it in GitHub Desktop.
Save vertexvaar/b3e64ba0201dcdd56bf90a9a2c68e533 to your computer and use it in GitHub Desktop.
Check if machine is connected to the internet
#!/bin/bash
# Taken from https://stackoverflow.com/a/44280885/2025722
# Added more devices (mainly from docker) to excluded list
find /sys/class/net/ -maxdepth 1 -mindepth 1 ! -name "*lo*" ! -name "veth*" ! -name "br-*" ! -name "docker*" -exec sh -c 'cat "$0"/carrier 2>&1' {} \; | grep -q '1'
#!/bin/bash
# Taken from https://stackoverflow.com/a/26820300/2025722
wget -q --spider http://google.com
if [ $? -eq 0 ]; then
echo "Online"
else
echo "Offline"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment