42

I'm writing a script that does dynamic DNS updates for me, but my server is behind a router, and so I need to determine my public IP.

There are websites like these ones that return some HTML, but I really don't want to bother parsing HTML when what the script needs to do is such a simple task.

How can I just get my IP address in plain text?

slhck
  • 235,242

4 Answers4

49

I can haz IP is a famous service that allows you to get your public IP address:

$ curl icanhazip.com
1.2.3.4

And that's it.

Since 2021 it is run by Cloudflare (some background info here).

If you have a public IPv6 address, it will return the IPv6 address by default, but you can get an IPv4 address by calling:

$ curl 4.icanhazip.com
1.2.3.4
slhck
  • 235,242
19

I use http://checkip.amazonaws.com/

curl -s http://checkip.amazonaws.com/

(This form miscounts the above 82 characters as 15 characters, so I have to enter an extra sentence.)

ShadSterling
  • 1,576
6

Or you could host your own. Use a free hosting company, and using PHP use a code like this:

<?php

echo $_SERVER['REMOTE_ADDR'];

?>
Reacen
  • 227
6

see page http://wtfismyip.com, http://wtfismyip.com/text actually on. Get ip address in the form of text. XML or JSON formats too.

or get http://checkip.dyndns.com/ but format is "Current IP Address: xxx.xxx.xxx.xxx"

mbi33
  • 61