Skip to content

Instantly share code, notes, and snippets.

@turbohz
Last active May 16, 2018 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turbohz/374b7983a00a7fc5d6f0fe79d2bce061 to your computer and use it in GitHub Desktop.
Save turbohz/374b7983a00a7fc5d6f0fe79d2bce061 to your computer and use it in GitHub Desktop.
Network diagnostics scripts
#!/bin/bash
ERROR_NO_NETWORK_CONTROLLER=1
ERROR_NO_NETWORK_INTERFACE=2
# check for network controller
dev_installed() { lspci -v | grep -q "Network controller\|Ethernet controller"; }
if ! dev_installed; then echo "No network controller detected."; exit $ERROR_NO_NETWORK_CONTROLLER; fi
# check for non virtual devices
physical_network_devices() {
# /sys/class/net contains symlinks for all available network devices
DEVICES=$(
for SYMLINK in /sys/class/net/*; do
readlink -e "$SYMLINK"
done
)
# physical device: /sys/devices/pci0000:00/0000:00:1c.0/0000:01:00.0/net/wlp1s0
# virtual device: /sys/devices/virtual/net/lo
echo "$DEVICES" |
grep -v virtual | #keep those not virtual
sed -E 's/.*\/([^\/]+)$/\1/' # keep just the name
}
PHYSICAL_NETWORK_INTERFACES=$(physical_network_devices)
if [ -z "$PHYSICAL_NETWORK_INTERFACES" ]; then echo "No physical network interface found."; exit $ERROR_NO_NETWORK_INTERFACE; fi
# check interfaces are up
for INTERFACE in $PHYSICAL_NETWORK_INTERFACES; do
UP=$(ip link show up "$INTERFACE")
[[ -z $UP ]] && echo "$INTERFACE is DOWN"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment