Commit 6ba8e4e0 authored by alozovskoy's avatar alozovskoy
Browse files
parent 0ba4f560
......@@ -8,8 +8,11 @@ digCmd=`which dig`
externalIp=`$digCmd +short myip.opendns.com @resolver1.opendns.com`
$ifconfigCmd \
| $grepCmd -B1 "inet addr" \
| $awkCmd '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' \
| $awkCmd -v exIp="$externalIp" -F: 'BEGIN {print "["} { print "{ \"interface\": \"" $1 "\", \"ip\": \"" $3 "\" },"} END {print "{ \"interface\": \"external\", \"ip\": \""exIp"\" } ]"}' \
| $trCmd -d '\r\n'
echo -n "["
for item in $($ifconfigCmd | $grepCmd -oP "^[a-zA-Z0-9:]*(?=:)")
do
echo -n "{\"interface\" : \""$item"\", \"ip\" : \"$( $ifconfigCmd $item | $grepCmd "inet" | $awkCmd '{match($0,"inet (addr:)?([0-9.]*)",a)}END{ if (NR != 0){print a[2]; exit}{print "none"}}')\"}, "
done
echo "{ \"interface\": \"external\", \"ip\": \"$externalIp\" } ]"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment