Last active
August 13, 2019 21:01
-
-
Save kepsic/e5c7566e4e8925f142827c57bbdccdb3 to your computer and use it in GitHub Desktop.
Detect 10G and 1G odd or even interface names under FreeBSD
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 | |
connected_interfaces=`ifconfig -a | awk '{FS=":";interfaces="";if (substr($1,length($1),1)%2 == 0) { | |
iface=$1; | |
if (iface ~ /^[a-z]+[0-9]/) { | |
getmedia="ifconfig " iface | |
while ((getmedia |getline) > 0) | |
if ($1 ~ /media/) { | |
media=$2 | |
connected_1g = match(media, /.*\(1000.*\).*/) | |
connected_10g = match(media, /.*\(10.*\).*/) | |
if (connected_1g != 0){ | |
interfaces=interfaces "1G="iface"\n" | |
} else if (connected_10g != 0) { | |
interfaces=interfaces "10G="iface"\n" | |
} | |
} | |
close(getmedia) | |
} | |
} | |
printf interfaces | |
}'` | |
sorted_interfaces=`echo $connected_interfaces|tr ' ' '\n'|sort -nr|cut -f2 -d"="` | |
int10G=`echo $sorted_interfaces|awk '{print $1}'` | |
int1G=`echo $sorted_interfaces|awk '{print $2}'` | |
echo $int10G | |
echo $int1G |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment