views:

637

answers:

4

I'm working on an IP geolocation library that uses the first three octets of an IPv4 address to determine a user's country, city, lat, lon, etc. Works like a charm.

But it doesn't handle IPv6 addresses, and I'd like it to do so.

Is there any way to transform an IPv6 address to get the equivalent of the first three octets of an IPv4 address, or are they on an entirely different numbering scheme, requiring a completely different ipgeo mapping?

+4  A: 

The typical IPv6 allocation is a /32 (four octets) to an Internet provider (which can be a multinational company), then /48 (six octets) to an end site (typically a client organization). You can get a starting point in the IANA list of delegated blocks.

This is only for registrations found in the databases of the RIR. Assignment to end users is typically not recorded so, my current address, 2a01:e35:8bd9:8bb0:92b:8628:5ca5:5f2b will tell you only that my provider's headquarters are in Paris (since it is a national company, the clients can be anywhere in France).

Another exception is the PI (Provider-Independent) assignements, which are typically /48.

Also, there exists many databases of geolocation for IPv4 and, to my knowledge, none for IPv6. You will have to do everything yourself.

To summary: more work than you apparently believe.

bortzmeyer
Exactly the info I need. The solution to my problem, then, is this: do not implement geolocation for IPv6 addresses.
benjismith
A: 

Since there does not appear to be an easy way to do this yet, perhaps we get the opportunity to do something that wasn't done in the case of IPv4 (*)

We could stop and ask ourselves whether this is a good idea.


(*) Or if it was done, it didn't work!

John Saunders
A: 

maxmind.com's geolocation services and libraries handle IPv6 OK. Maybe their stuff is an option for you. (I don't have any affiliation with them.)

Noah
+1  A: 

Friendly correction to Noah's comment (Jun 3 at 7:57)--

Per MaxMind's client services department (emphasis mine): "IPv6 is currently NOT supported. At some time in the future, we do plan to implement it but we do not have a date at this time."

cjo30080