Skip to content

Instantly share code, notes, and snippets.

@darkphase
Last active January 23, 2016 02:01
Show Gist options
  • Save darkphase/67d7ec22d47dbebd329e to your computer and use it in GitHub Desktop.
Save darkphase/67d7ec22d47dbebd329e to your computer and use it in GitHub Desktop.
#!/bin/bash
red="\033[31m"
green="\033[32m"
blue="\033[34m"
yellow="\033[33m"
reset="\033[0m"
echo -e $green"Detected Interfaces"$reset
echo ""
# cmd="cat ifconfig.out"
cmd="ifconfig"
echo ee | awk '
BEGIN { RS = "" ; FS = "\n" }
{
while ( "'"$cmd"'" | getline ){
# print $0
if ( $1 !~ /LOOPBACK/ ){
split($1,arr," ")
print "'"$blue"'"arr[1]"'"$reset"'"
for(i = 1; i <= NF; i++) {
split($i,arr," ")
switch ( arr[1] ) {
case "inet":
print "'"$red"'" "IPV4:" "'"$reset"'" "\n IP: " "'"$yellow"'" arr[2] "'"$reset"'" "\n NM: "arr[4]"\n BC: "arr[6]
break
case "inet6":
print "'"$red"'" "IPV6:" "'"$reset"'" "\n IP: "arr[2]"\n PL: "arr[4]
break
case "ether":
print "'"$red"'" "MAC: " "'"$reset"'" arr[2]
break
default:
}
}
print ""
}
}
}'
@darkphase
Copy link
Author

RS : Record Seperator
FS : Field Seperator
NF : Number of Fields

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment