Skip to content

Instantly share code, notes, and snippets.

@vivien
Created January 9, 2015 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vivien/f00786da641c3aa6275d to your computer and use it in GitHub Desktop.
Save vivien/f00786da641c3aa6275d to your computer and use it in GitHub Desktop.
ip address blocklet
#!/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