scripts/getiface.sh

18 lines
354 B
Bash
Raw Permalink Normal View History

2014-07-09 15:18:02 +02:00
#!/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}'