
Your IP. In JSON - zcopley
http://jsonip.com/
======
geuis
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
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.

------
mike-cardwell
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
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...](http://stackoverflow.com/questions/477816/the-right-json-content-type)

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

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

~~~
callahad
You could also use: <http://www.whatismyip.com/automation/n09230945.asp>

~~~
pavel_lishin
What a convenient URL to remember.

~~~
spicyj
For a while, <http://whatismyip.org/> returned your IP in plain text, but no
longer.

------
hm2k
<http://whatismyip.akamai.com/>

Pretty reliable.

~~~
IsaacSchlueter
Parsing text is too hard. It'd be easier if it was in JSON.

~~~
gulbrandr
Oh I see! This is what you are looking for: <http://www.showmyip.com/xml/>

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

------
lurchpop
add a jsonp callback option like <http://jsonip.com/?callback=alert>

~~~
rburgt
its there already: <http://jsonip.com/nameofcallbackfunction>

~~~
qixxiq
You should probably include the ?callback= functionality anyway. A great deal
of libraries assume it will be a get variable, and cater for it specially

i.e. jQuery with <http://jsonip.com/?callback=>?

~~~
NovaDesu
I actually made something like this a while ago.

<http://demontunes.com/api/?g=ip> // plain ip

[http://demontunes.com/api/?g=ip&format=json](http://demontunes.com/api/?g=ip&format=json)
// in json

[http://demontunes.com/api/?g=ip&format=json&callback...](http://demontunes.com/api/?g=ip&format=json&callback=hello)
// with a callback

------
mrspeaker
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
Openkeyval is kind of cool except that it uses Memcache as the storage
platform--i.e. no guarantees of persistance.

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

~~~
cake
Could anyone list some practical uses ?

~~~
Corrado
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
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?

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

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

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

~~~
innes
This, I think:

<http://en.wikipedia.org/wiki/JSON#JSONP>

 _Under the same origin policy, a web page served from server1.example.com
cannot normally connect to or communicate with a server other than
server1.example.com. An exception is the HTML <script> element._

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

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

~~~
JoachimSchipper
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
"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
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?

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

------
gikrauss
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
<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
What's your business model though?

(Kidding.)

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

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

------
nphase
Also, icanhazip.com

~~~
burke
I'll probably start using this one. Nice short domain name.

------
ptn
It got mine wrong.

------
jparicka
Haha .. very cool! :-))

