Created
April 27, 2023 11:01
-
-
Save anzz1/15d5b22f299dc3f94397896380b368d6 to your computer and use it in GitHub Desktop.
ip.sh
This file contains hidden or 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/sh | |
ipvalid() { | |
if expr "$1" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then | |
return 0 | |
fi | |
return 1 | |
} | |
# IP=$(ifconfig wlan0 | grep -m1 'inet addr:' | cut -d: -f2 | cut -d' ' -f1) | |
IP=$(ip route get 255.255.255.255 | awk '{print $NF;exit}') | |
if ipvalid "$IP"; then | |
echo "l: $IP" | |
fi | |
# EXT_IP=$(nslookup myip.opendns.com resolver4.opendns.com | awk '/Address 1:/{i++}i==2{print $3;exit}') | |
# EXT_IP=$(dig @resolver4.opendns.com myip.opendns.com +short -4) | |
EXT_IP=$(echo -ne "GET / HTTP/1.1\r\nHost: whatismyip.akamai.com\r\nAccept: text/plain\r\nConnection: close\r\n\r\n" | nc -w1 whatismyip.akamai.com 80 | tail -1) | |
if ipvalid "$EXT_IP"; then | |
echo "e: $EXT_IP" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment