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

    Get Your IP Address from a Command Line

    Scheduled Pinned Locked Moved IT Discussion
    curl
    15 Posts 4 Posters 2.9k Views
    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.
    • 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