Skip to content

Instantly share code, notes, and snippets.

@ViKingIX
Created January 2, 2022 00:59
Show Gist options
  • Save ViKingIX/d4ece6c06c208deb116a9aaa8c74d5d5 to your computer and use it in GitHub Desktop.
Save ViKingIX/d4ece6c06c208deb116a9aaa8c74d5d5 to your computer and use it in GitHub Desktop.
function lanip()
{
ip -4 addr show en6 | awk '/inet/ { print $2; }' | awk -F/ '{ print $1; }'
}
function gw() {
ip route | awk '/default/ { print $3; }'
}
function langw()
{
ip route | awk '/default/ && /en6/ { print $3; }'
}
function wifiip()
{
ip -4 addr show en0 | awk '/inet/ { print $2; }' | awk -F/ '{print $1;}'
}
function wifi_wan()
{
dig -b $(wifiip) +short myip.opendns.com @resolver1.opendns.com
}
function pubip()
{
intf=$(ip route | head -n 1 | awk '{ print $5; }')
if [[ $intf == "en6" ]]; then
local_ip=$(lanip)
elif [[ $intf == "en0" ]]; then
local_ip=$(wifiip)
fi
dig -b $local_ip +short myip.opendns.com @resolver1.opendns.com
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment