Last active
May 16, 2018 12:43
-
-
Save turbohz/374b7983a00a7fc5d6f0fe79d2bce061 to your computer and use it in GitHub Desktop.
Network diagnostics scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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