#!/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}'