added getiface.sh
This commit is contained in:
parent
59184d7b19
commit
23d5fc6e4d
2 changed files with 19 additions and 1 deletions
18
getiface.sh
Executable file
18
getiface.sh
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Shows which interface would be used
|
||||
# to connecto to an IP address/hostname
|
||||
|
||||
INPUT=$1
|
||||
|
||||
if [ -z $INPUT ]; then
|
||||
echo "Need an IP/hostname"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ $(echo $INPUT | grep -c '[a-z]') -gt 0 ]; then
|
||||
INPUT=$(dig +short $INPUT | tail -1)
|
||||
fi
|
||||
|
||||
echo -n "Interface: "
|
||||
ip -o route get $INPUT | perl -nle 'if(/dev\s+(\S+)/) {print $1}'
|
||||
Loading…
Add table
Add a link
Reference in a new issue