Last active
August 29, 2015 14:19
-
-
Save vkushnir/2760480eefa824256644 to your computer and use it in GitHub Desktop.
Getting data from P interface
This file contains hidden or 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
| get_ether() { | |
| # 0-<interface>, 1-<mac address>, 2-<broadcast> | |
| local net[0]=$1 | |
| net[1]=`ip -0 -o addr show dev ${net[0]} | grep -oiP '(?<=link\/ether)\s+([0-9a-f]{2}\:?){6}' | tr -d '[[:space:]]'` | |
| net[2]=`ip -0 -o addr show dev ${net[0]} | grep -oiP '(?<=brd)\s+([0-9a-f]{2}\:?){6}' | tr -d '[[:space:]]'` | |
| echo "${net[@]}" | |
| } | |
| get_ipv4() { | |
| # 0-<interface>, 1-<full network>, 2-<interface ip>, 3-<network bits>, 4-<broadcast> | |
| local net[0]=$1 | |
| net[1]=`ip -4 -o addr show dev ${net[0]} | grep -oiP '(?<=inet)\s+([0-9]+\.?)+\/[0-9]+' | tr -d '[[:space:]]'` | |
| net[2]=`echo ${net[1]} | cut -f1 -d'/'` | |
| net[3]=`echo ${net[1]} | cut -f2 -d'/'` | |
| net[4]=`ip -4 -o addr show dev ${net[0]} | grep -oiP '(?<=brd)\s+([0-9]+\.?)+' | tr -d '[[:space:]]'` | |
| echo "${net[@]}" | |
| } | |
| get_ipv6() { | |
| # 0-<interface>, 1-<full network>, 2-<interface ip>, 3-<network bits> | |
| local net[0]=$1 | |
| net[1]=`ip -6 -o addr show dev ${net[0]} | grep -oiP '(?<=inet6)\s+([0-9a-f]+\:*)+\/[0-9]+' | tr -d '[[:space:]]'` | |
| net[2]=`echo ${net[1]} | cut -f1 -d'/'` | |
| net[3]=`echo ${net[1]} | cut -f2 -d'/'` | |
| echo "${net[@]}" | |
| } | |
| get_dnsv4() { | |
| local i=0 | |
| local ip="" | |
| local dns="" | |
| for ip in `grep -is nameserver /etc/resolv.conf | grep -oE '([0-9]+\.?)+'` | |
| do | |
| dns[$i]=$ip | |
| ((i++)) | |
| done | |
| echo "${dns[@]}" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment