cross-posted from: https://gekinzuku.com/post/98403

While it’s easy to get an IP address from popular websites such as whatismyip.com, it’s not often friendly to a context where you might need to get your IP address for command line tools.

In order to grab your IP address via the command line, there’s a page on a site called ipinfo.io/ip which only contains body content corresponding to your IP address. The easiest way to fetch that data is with the curl command (should be available on both Windows and Linux).

curl ipinfo.io/ip

It may also be beneficial to add this to your .bashrc or .aliasrc on Linux systems with something like

alias myip="curl ipinfo.io/ip"

Now you have an easy way to grab your IP address from the command line!

  • ono@lemmy.ca
    link
    fedilink
    English
    arrow-up
    7
    ·
    edit-2
    1 year ago
    curl --silent https://myipv4.p1.opendns.com/get_my_ip | jq --raw-output '.ip'
    curl --silent https://eth0.me
    curl --silent https://ifconfig.me/ip
    curl --silent https://ipecho.net/plain
    curl --silent https://ipinfo.io/ip
    dig @resolver4.opendns.com myip.opendns.com +short
    

    That last one is generally much faster than the rest.

    Also, you can add -w '\n' to curl commands to make it add a newline.