added getiface.sh

This commit is contained in:
Oliver Ladner 2014-07-09 15:18:02 +02:00
commit 23d5fc6e4d
2 changed files with 19 additions and 1 deletions

2
README
View file

@ -15,4 +15,4 @@ policyd-550.sh Grep the mail.log for e-mails rejected by policyd-weight and sc
rblcheck.sh Check if your server is listed on an DNSBL
tls_stats.sh If you own a mailserver sending e-mails via TLS, show stats of peers
www-perms.sh Analyze your $documentroot for files writable by www user/group
getiface.sh Shows which interface would be used to connect to a specific host/IP

18
getiface.sh Executable file
View 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}'