Get Your IP Address from a Command Line
-
Sitting at a command prompt on Linux and want to know your WAN IP address? Try this...
curl ifconfig.co
-
I love this one, super handy. I hate having to go look that up when all you need is your outside IP address. So handy.
-
Good find.
-
Saved this command for my future reference.
-
It's buried in there in the HTML. Does curl strip that out?
-
That URL is designed to just return only the IP address. Curl is just a text browser. If you weren't at a command line you could use any number of tools to look at the result. Curl is just handy because it is so ubiquitous and that URL is used because unlike most webpages that provide that info, this one doesn't provide anything else.
-
My guess is that it detects curl and changes what it sends based on that.
-
Yeah, curl must be identifying itself (maybe as a browser type). When I use Invoke-Webrequest I'm getting the full HTML. I do have a PowerShell equivalent to do this:
http://community.spiceworks.com/scripts/show/2327-what-is-my-ip-get-whatismyip
But would have been cool to have a one-liner
-
You can use Curl on Windows too
-
Third party, bleh
-
OK, doesn't look like it's user agent it's looking at. I've fed a couple of different curl agents into it and still getting the full HTML:
http://www.useragentstring.com/pages/curl/Could prolly feed this into a RegEx pretty easily to pull the number out of it... but while it's the letter of the law (one-liner) it's hardly the spirit!
-
That's weird, I wonder why it comes back so clean in Curl then.
-
Not sure, but I did find that this works though:
(Invoke-WebRequest ifconfig.me/ip).Content
-
@Martin9700 said:
(Invoke-WebRequest ifconfig.me/ip).Content
Sweet, just tried it here, works great.
-
@scottalanmiller said:
@Martin9700 said:
(Invoke-WebRequest ifconfig.me/ip).Content
Sweet, just tried it here, works great.
Still like the output from my script better--more PowerShellish. It's also quite a bit faster (the ifconfig.me site seems pretty sluggish).