Created
January 9, 2015 06:11
-
-
Save vivien/f00786da641c3aa6275d to your computer and use it in GitHub Desktop.
ip address blocklet
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
#!/bin/bash | |
# use the provided interface, otherwise the first default device | |
if [[ -n $BLOCK_INSTANCE ]] | |
then | |
IF=$BLOCK_INSTANCE | |
else | |
IF=$( ip route | awk '/^default/ { print $5 ; exit }' ) | |
fi | |
case $1 in | |
-4) | |
AF=inet ;; | |
-6) | |
AF=inet6 ;; | |
*) | |
AF=inet6? ;; | |
esac | |
# if no interface is found, use the first device with a global scope | |
ADDR=$( ip addr show $IF | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit" ) | |
case $BLOCK_BUTTON in | |
3) echo $ADDR | xclip -q -se c ;; | |
esac | |
echo $ADDR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment