-
-
Save gromnitsky/da6b8504fe5d17d584b260e2e01919f3 to your computer and use it in GitHub Desktop.
print all the relevant info about all the nics; useful for machines w/ multiple network cards; linux only
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/sh | |
errno=0 | |
sys=/sys/class/net | |
# $1 == nic | |
dump() { | |
[ -d "$sys/$1" ] || { echo "$1 is absent" 1>&2; errno=2; return; } | |
echo Name "$1" | pp | |
echo MAC "`cat "$sys/$1/address"`" | pp | |
echo Driver "`uevent "$1" DRIVER`" | pp | |
echo pci_id "`uevent "$1" PCI_ID`" | pp | |
echo usb_id "`usb_id "$1"`" | pp | |
(pci "$1" || usb "$1") | pp | |
} | |
# $1 == nic | |
pci() { | |
local dev=`uevent "$1" PCI_ID` | |
[ ! -z "$dev" ] && /usr/sbin/lspci -d "$dev" -vmmk 2>/dev/null \ | |
| gawk 'match($0, /^(S?Vendor|S?Device|Rev):(.*)/, r) { printf("%s %s\n", r[1], r[2]) }' | |
} | |
# $1 == nic | |
usb() { | |
local dev=`usb_id "$1"` | |
[ ! -z "$dev" ] && lsusb -v -d "$dev" 2>/dev/null | awk '/idVendor|id?Product|iManufacturer|iSerial/ {printf $1; $1=""; $2=""; print $0}' | |
} | |
# $1 == nic | |
usb_id() { uevent "$1" PRODUCT | awk -F/ '{printf("%s:%s", $1, $2)}'; } | |
# $1 == nic, $2 == key | |
uevent() { awk -F= '/^'"$2"'/ {print $2}' "$sys/$1/device/uevent" 2>/dev/null; } | |
pp() { awk '{if ($2 != "") { printf("%-15s", $1); $1=""; print $0} }'; } | |
nics=$* | |
[ -z "$nics" ] && { nics=`(cd $sys && echo *)` || exit 1; } | |
idx=0; for val in $nics; do | |
[ $idx -ne 0 ] && echo '' | |
dump "$val" | |
idx=1 | |
done | |
exit $errno |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment