-
-
Save Avaray/b0bd37cf1b78b30f535476b3d0da62e1 to your computer and use it in GitHub Desktop.
[BASH] Get public IP address
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 | |
S1='whatismyip.akamai.com' | |
S2='icanhazip.com' | |
S3='ifconfig.me' | |
IP=$(curl -sk $S1) | |
IP_regex='^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' | |
if [[ ! $IP =~ $IP_regex ]]; then | |
IP=$(curl -sk $S2) | |
if [[ ! $IP =~ $IP_regex ]]; then | |
IP=$(curl -sk $S3) | |
fi | |
fi | |
if [[ $IP =~ $IP_regex ]]; then | |
echo $IP | tr -d '[:space:]' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also use my GIP, a CLI tool for NodeJS.