Settings

Theme

Your IP. In JSON

jsonip.com

160 points by zcopley 15 years ago · 71 comments

Reader

geuis 15 years ago

Whoa. I wrote jsonip a few months ago and never expected it to get noticed. What a pleasant surprise!

Here's the original post with some usage details. http://news.ycombinator.net/item?id=1896015

This is actually running on node.js. If anyone finds a bug or has some suggestions, email me or leave a tweet @geuis.

  • btubbs 15 years ago

    If there's a ?callback=something in the query string, you could wrap the JSON in that callback so the service can be used with JSONP.

  • webXL 15 years ago

    Node.js - that was my first guess. Nice example of utility computing!

mike-cardwell 15 years ago

Some suggestions:

Make jsonip.com dual stack IPv4/IPv6 and work for IPv6 addresses too. Return some other useful IP information, such as the PTR, the domain name part of the PTR, and the country code and name.

Example: https://grepular.com/ipinfo

EDIT: Don't use that URL for your own stuff or I'll block it. I only put it there as an example of how the JSON should be returned.

EDIT2: Might be useful if it included the IP addresses from any X-Forwarded-For HTTP header too.

  • sghael 15 years ago

    This brings up something I'm waffling on. Whats the correct content type for JSON?

    in your example returning "Content-Type: text/plain; charset=UTF-8" which is nice because FF knows to render it in the browser (good for debugging atleast).

    But votes on SO seem to indicate it should be "application/json"

    http://stackoverflow.com/questions/477816/the-right-json-con...

  • geuis 15 years ago

    Thanks Mike. I'll start working some of these in over the next few days

  • gmac 15 years ago

    Some of this is already available elsewhere: I've been using http://ipinfodb.com/ to decide whether to show a region-specific alert on the front page of http://mappin.es

  • IgorPartola 15 years ago

    IPv6 is silly to support. There are no IPv6 NATs, so you should know your IPv6 address.

    • jedsmith 15 years ago

      There are two scenarios where such a site has been useful to me:

      1) Making sure I deprecated the right addresses in the Linux kernel, and that the kernel was using the outgoing address I wanted instead of the one it would pick via RFC 3484, and

      2) Making sure IPv6 browsing is working since turning off v4 is a pain in the ass (in the setups I've had to troubleshoot v6 on, not my home network, where it's much easier).

    • metageek 15 years ago

      There shouldn't be IPv6 NATs, but I expect there will be once it actually gets deployed.

drdaeman 15 years ago

{ip: "192.168.100.2, xxx.xxx.xxx.xxx"}. Why not change it to {ip: ["192.168.100.2", "xxx.xxx.xxx.xxx"]}?

Also, while I don't know any practical use, IPv6 support would be nice.

jjguy 15 years ago

That's clever and useful. Thanks. I've used http://checkip.dyndns.org for this problem for years, but this is an improvement. Checkip:

    >>> url = urllib2.urlopen("http://checkip.dyndns.org")
    >>> url.read()
    '<html><head><title>Current IP Check</title></head><body>Current IP Address: 192.168.0.1</body></html>\r\n'
Details here: http://www.dyndns.com/developers/checkip.html

It's not as easy to parse as JSON, but nor is it very difficult. The format has not changed in years; I've got a regex running I haven't needed to adjust since day 1.

hm2k 15 years ago

http://whatismyip.akamai.com/

Pretty reliable.

hunterp 15 years ago

While it is minimalist, it would be even more minimalist to just return the ip with no json wrapper.

lurchpop 15 years ago

add a jsonp callback option like http://jsonip.com/?callback=alert

mrspeaker 15 years ago

Great idea by the way! I don't know what for... yet... but great idea! For some reason I have a strange urge to combine this with http://openkeyval.org/

  • apgwoz 15 years ago

    Openkeyval is kind of cool except that it uses Memcache as the storage platform--i.e. no guarantees of persistance.

vain 15 years ago

i am missing something here. why does everyone here seem to think this is cool?

  • cake 15 years ago

    Could anyone list some practical uses ?

    • Corrado 15 years ago

      I built some WebSocket code that calls back to the server. I can't hardcode the "server" ip address because I want to deploy it to different places at different times. Sometimes I'm working on my laptop, sometimes its running on Amazon EC2, etc. So, with something like this I am able to build my Javascript so it always knows how to get back to the server.

      <yea, I know there are lots of ways to do this, but this is the one I chose. :) sue me. >

      • Tichy 15 years ago

        So myipinjosin returns the server's IP address? I thought it would return the clients IP address. (Link is broken atm).

        For your use case, relative URLs seem the better solution?

    • joebananas 15 years ago

      Finding your own external, visible-to-the-internet IP. You're almost always behind some router these days, so using ifconfig or whatever is pretty useless.

there 15 years ago

if you need geolocation information through javascript, you can use maxmind's free one:

http://j.maxmind.com/app/geoip.js

  • pedrocr 15 years ago

    Outputting javascript code instead of something parseable (json probably) seems like a very bad idea. Are you really willing to eval code from a site outside your control?

    A simple line-by-line regex loop should be enough to parse this though.

  • cappaert 15 years ago

    This is perfect. I've been looking for an easy way to find user location (city, state) based on IP address, without having to scrape a IP lookup service for it.

    Great find!

petercooper 15 years ago

xmlip.com, yamlip.com, and plaintextip.com are all available, by the way.

floatingatoll 15 years ago

i see a dancing turtle at kame, but my ipv6 address is not present in the json.

  • JoachimSchipper 15 years ago

    Well, yes - jsonip.com has no AAAA records. I'm not sure that reporting (only! - it only knows where the connection is from) an IPv6 address is all that useful, either.

    That said, there's space for a jsonip6.com...

    • enneff 15 years ago

      "I'm not sure that reporting [only] an IPv6 address is all that useful"

      Why not? It's useful to me, and anyone else who has an IPv6 address. The future is now. Get with the program.

      • maggit 15 years ago

        I'm not in the future yet, but I was under the impression that with IPv6 you would actually know your own public address, because there is no need for NAT. Is this not correct?

        • dedward 15 years ago

          True in theory, likely in practice.

          NAT will still be possible - just not necessary for conserving address space.

          But... imagine trying to get your call-center staff to ask the customer to read back their local IPv6 address so you can troubleshoot. That's going to be bad enough. Then consider there may be proxies in the way, intentionally or otherwise, so you probably want to know the IP address the customer is hitting your product with, not their computer.

          Most of us on HN are probably smart enough to find out our own IPs a half dozen ways - it's the 3rd party support that's tougher.

        • mryall 15 years ago

          Not only do you know it, you get it tattooed on your body. If there's no need to change IP addresses, you might as well make it permanent.

          • JoachimSchipper 15 years ago

            IPv6 addresses are statically allocated (well, in the IPv6 proponents' designs - in reality, we may end up with DHCPv6 and the like), but almost always provider-allocated (PA), not provider independent (PI); so you'll have to give it back to your ISP when you switch.

            This is a good thing, by the way; PI space consumes memory on the backbone routers (they can't just send it to your ISP, after all - the whole point is that you can take it with you). Of course, PA space is just part of a larger allocation to your provider.

            In other words, don't get the tattoo.

      • JoachimSchipper 15 years ago

        For one, most people with IPv6 have a fixed address. Also, the future is not very well distributed.

  • geuis 15 years ago

    I will look into adding ipv6 support

gikrauss 15 years ago

I think I'll replace whatsmyip.com for this: alias whatsmyip="curl -s http://jsonip.com | grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' -o"

A simple way of accessing your public IP from bash (for some reason I need to do that a lot!)

powertower 15 years ago

http://myip.wampdeveloper.com/

Only the ip, no html tags, no formating, nothing but 1 string returned.

Also correctly deals with x-forwarded-for and all the other client/proxy/remote header fields.

Absolute minimum way of returning an IP address.

soulclap 15 years ago

What's your business model though?

(Kidding.)

billpg 15 years ago

Is there an HTTPS service planned? Without it, you may just be seeing the IP of a transparent proxy server.

  • pmjordan 15 years ago

    HTTPS can be proxied, too, transparent or not, and you'll end up with the proxy's IP. (as the HTTP headers are encrypted along with everything else, the proxy can't even include an 'X-Forwarded-For:' header) Still useful for maintaining the full 'lock' icon when embedding in other websites, though including jsonp in an https site somewhat defeats the purpose. You'd need CORS on the server for it to be useful.

    • billpg 15 years ago

      An HTTPS proxy can only work when the client explicitly configures it. A proxy that can't cache or modify traffic is more like a NAT router than a proxy.

      (I imagine getting the IP of the other side of any NAT router is point of this service.)

      • pmjordan 15 years ago

        You can transparently proxy arbitrary network traffic. See https://github.com/apenwarr/sshuttle for an example. FWIW, I'm only pointing out that HTTPS wins you exactly nothing compared to HTTP for this particular purpose. The concept of the "correct" IP address in the context of NAT and proxies is hazy at best anyway.

        • billpg 15 years ago

          There are ISPs that will route all (or some) port 80 traffic into a bank of caching proxies but route traffic for all other ports normally.

          (GRC.COM's 'Shields Up' service makes a point of using HTTPS to make sure it's testing your external IP rather than a random proxy server.)

          I suppose it depends on what you actually want to use the returned IP for. As you say, the concept is hazy.

  • dedward 15 years ago

    Which might be exactly what you want if you are troubleshooting HTTP issues with customers "Go to page X and tell me what it says" rather than "what is your IP" is much more reliable.

    If there's a proxy, there's a proxy - but I can't troubleshoot the customer's connectivity issue without that.

nphase 15 years ago

Also, icanhazip.com

ptn 15 years ago

It got mine wrong.

jparicka 15 years ago

Haha .. very cool! :-))

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection