Live data from Hacker News

Your IP. In JSON

jsonip.com

61–70 of 72 posts

Re: Your IP. In JSON

#62
post #34

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…

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

The correct content-type (MIME type) is indeed "application/json" (edit: downcased JSON, not sure why I made that typo). http://tools.ietf.org/html/rfc4627

Additionally, if no encoding is specified, UTF-8 should be assumed when dealing with JSON.

Re: Your IP. In JSON

#63
post #55
post #49

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

Could anyone list some practical uses ?

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.

Re: Your IP. In JSON

#64
post #56
post #55

Earlier quoted context omitted.

Could anyone list some practical uses ?

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.

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?

Re: Your IP. In JSON

#65
post #28

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() ' Current IP Check Current IP Address: 192.168.0.1 \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 yea…

You could also use: http://www.whatismyip.com/automation/n09230945.asp

What a convenient URL to remember.

Re: Your IP. In JSON

#66
post #34

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…

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

application/json

Re: Your IP. In JSON

#67
post #28

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() ' Current IP Check Current IP Address: 192.168.0.1 \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 yea…

Try this: http://myip.dnsomatic.com/

Documented here: http://dnsomatic.com/wiki/api#detecting_changes

Re: Your IP. In JSON

#68
post #52

if you need geolocation information through javascript, you can use maxmind's free one: http://j.maxmind.com/app/geoip.js

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.

Re: Your IP. In JSON

#69
post #16

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.

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.
Post reply on HN