ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Get Your IP Address from a Command Line

    IT Discussion
    curl
    4
    15
    2.8k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by

      Sitting at a command prompt on Linux and want to know your WAN IP address? Try this...

      curl ifconfig.co
      
      1 Reply Last reply Reply Quote 3
      • scottalanmillerS
        scottalanmiller
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • Reid CooperR
          Reid Cooper
          last edited by

          Good find.

          1 Reply Last reply Reply Quote 0
          • JoyJ
            Joy
            last edited by

            Saved this command for my future reference.

            1 Reply Last reply Reply Quote 0
            • M
              Martin9700
              last edited by

              It's buried in there in the HTML. Does curl strip that out?

              1 Reply Last reply Reply Quote 0
              • scottalanmillerS
                scottalanmiller
                last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • scottalanmillerS
                  scottalanmiller
                  last edited by

                  My guess is that it detects curl and changes what it sends based on that.

                  1 Reply Last reply Reply Quote 0
                  • M
                    Martin9700
                    last edited by

                    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 🙂

                    1 Reply Last reply Reply Quote 0
                    • scottalanmillerS
                      scottalanmiller
                      last edited by

                      You can use Curl on Windows too 🙂

                      1 Reply Last reply Reply Quote 0
                      • M
                        Martin9700
                        last edited by

                        Third party, bleh 🙂

                        1 Reply Last reply Reply Quote 0
                        • M
                          Martin9700
                          last edited by

                          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!

                          1 Reply Last reply Reply Quote 0
                          • scottalanmillerS
                            scottalanmiller
                            last edited by

                            That's weird, I wonder why it comes back so clean in Curl then.

                            1 Reply Last reply Reply Quote 0
                            • M
                              Martin9700
                              last edited by

                              Not sure, but I did find that this works though:

                              (Invoke-WebRequest ifconfig.me/ip).Content

                              1 Reply Last reply Reply Quote 1
                              • scottalanmillerS
                                scottalanmiller
                                last edited by

                                @Martin9700 said:

                                (Invoke-WebRequest ifconfig.me/ip).Content

                                Sweet, just tried it here, works great.

                                M 1 Reply Last reply Reply Quote 0
                                • M
                                  Martin9700 @scottalanmiller
                                  last edited by

                                  @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).

                                  1 Reply Last reply Reply Quote 0
                                  • 1 / 1
                                  • First post
                                    Last post