Last active
January 3, 2024 06:24
-
-
Save notsle/a5561aad60ecfc272d8e to your computer and use it in GitHub Desktop.
Get Public IP address with curl and ipchicken.com
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
curl -s https://ipchicken.com | egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}' |
Thanks. I updated my original with https
Perfect!
This is great, thank you!
This gist is cool because it demonstrates some simple web scraping that can be accomplished using egrep
. In practice, I would probably use the following if I were seeking to fetch my public IP address in a shell script:
# show public IP
curl -s ifconfig.me
# use inside a variable
my_ip=$(curl -s ifconfig.me)
echo "My public IP address: $my_ip"
if you don't have egrep installed or don't wanna deal with grep in general, you can do this;
curl ipaddress.ai
wget can also be used;
wget -qO- ipaddress.ai
or visit ipaddress.ai
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your script as it provides a nice example of using regular expressions to extract info from HTML. I had to do a
curl -sL http://ipchicken.com
to follow redirects to make it work and then I realized that ipchicken.com is now using https . The updated script would thus be:curl -s https://ipchicken.com | egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'