Last active
July 13, 2016 18:53
-
-
Save rafael-neri/7d79fc3508352270f109196b2d9fc4e1 to your computer and use it in GitHub Desktop.
Check Default Interface To Internet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# host we want to "reach" | |
host=google.com | |
# get the ip of that host (works with dns and /etc/hosts. In case we get multiple ipaddresses, we just want one of them | |
host_ip=$(getent ahosts "$host" | head -1 | awk '{print $1}') | |
# only list the interface used to reach a specific host/IP. We only want the part between dev and src (use grep for that) | |
ip route get "$host_ip" | grep -Po '(?<=(dev )).*(?= src)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment