21

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?

3
  • 1
    Can you tell me what part of the IPv6 specifications has led you to believe that there's any correspondence between IPv6 address and geographic location? Jul 22, 2009 at 2:13
  • You may want to see the following, at least with respect to Mobile IPv6: rfc-editor.org/rfc/rfc4882.txt Jul 22, 2009 at 2:18
  • Hmmmmmmmm... Well, there's nothing inherent about the IPv4 specification that implies any information about geographic location. It's a convenient coincidence (or inconvenient, if you don't want people to know what city you're in) that geolocation can be accomplished with IPv4, based only on the fact that IP address blocks tend to be allocated to regional ISPs. And actually, I wasn't asking about an inherent geolocation capability in IPv6, just for some transformation from an IPv6 address to the equivalent first-three-octets of an IPv4 address, if such a mapping exists.
    – benjismith
    Jul 22, 2009 at 3:04

8 Answers 8

17

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.

1
  • 2
    Exactly the info I need. The solution to my problem, then, is this: do not implement geolocation for IPv6 addresses.
    – benjismith
    Jul 24, 2009 at 5:33
2

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

0
2

IPv6 uses a completely different addressing scheme compared to IPv4. There is no way you can map IPv6 addresses to IPv4 addresses, with one exception. If you see IPv6 addresses that start with 2002: then the address is a 6to4 address. You won't see a lot of those in use probably and they are being deprecated, but those are mappable to IPv4.

Each user of a public IPv4 address can use a /48 (65536 subnets) of IPv6 space. Those addresses always begin with 2002: and the next two hexadecimal numbers are the IPv4 address. So 2002:5389:1164: corresponds to my own webserver's IPv4 address (83.137.17.100):

0x53 = 83
0x89 = 137
0x11 = 17
0x64 = 100

But all 'normal' IPv6 addresses are completely unrelated to any IPv4 addresses. At least in a standard way. An ISP could define a relationship between IPv4 and IPv6 addresses when rolling out IPv6 to its customers. But you won't know about that relationship so it will be useless to you...

1

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

0
1

If you read a number of ipv6, address and transition mechanism on wiki, you will find a few IPv6 addresses patterns that may infer an ipv4 (siit, ipv4-mapped ipv6, nat64, the 2002:* thing written above, etc.). One of them to start: http://en.wikipedia.org/wiki/IPv6_transition_mechanisms

I would not count on these schemes to be popular enough to do the usual geo reports, fraud protection, or incident detection, but I would definitely give precedence to an ipv4 geo lookup for such inferred ipv4 addresses over an ipv6 geo lookup (assuming the ipv4 db is more complete).

My concern with ipv6 geo information is the incredibly large number of subnets. Databases will get larger (more ip ranges), that is expected but for the same amount of terminal geo information, the databases will be sparser and the deeper tree is also longer to iterate (for implementation that uses binary or radix trees) which implies some performance cost. Geo databases using sql tables with ip ranges will probably also suffer, since we don't have big-bigint of 128bits, that I know of, to use arithmetic.

Another concern is the mobiles: ipv6 is designed to facilitate roaming, if I am not mistaking. You could change cell towers and keep your IP. maybe even while changing city, region or country. I somewhat doubt that since that a strong address affinity was the purpose of a MAC address. Ip addresses exist precisely for routing purpose, but I think it is fair to mention they could become invariant enough to cripple the accuracy of geo location, obviously.

I feel the collaboration of user agents/browsers at the application layer (some geo location header for example) is likely the future, even if this can be spoofed by mischievous people.

1

There is a protocol called Referral Whois which allows providers to publish IP geolocation information and others to retrieve it.

For example, my current IP 2001:470:b4ea:babe:d57:15c8:97b:60c9 belongs to Hurricane Electric in the US. The actual server where the IPv4-IPv6 tunnel I use terminates is in Switzerland, but I am in Austria. HE publishes all of this, so if you enter the IP in a tool supporting RWhois like this, you will find the contact data of HE and somwhere near the bottom you see

contact:Name:Private Customer - Hurricane Electric

contact:Street-Address:Private Residence

contact:Country-Code:AT

which is my location.

Not many providers do publish that, and not many geolocation tools support it, but at least it exists.

Most of the IP geolocation providers (of those who support IPv6, some still don't) put this IP to Switzerland, some even in the US.

-1

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!

-2

geolocation is bad, mmkay? the internet is location-agnostic, and i have never seen geolocation used for something non-trivial-non-evil. that is, the only good applications i've seen (language selection) were trivial (could just as easily be a dropdown). many evil applications exist (this video not available in your country, targeting my physical location for ads and tracking) we can't discourage something like this from existing, but we should push to make it illegal or at least socially unacceptable to use.

7
  • 12
    I completely disagree. Geolocation is extremely valuable for companies for many reasons. One easy example is fraud prevention.
    – snurre
    Mar 29, 2011 at 12:22
  • 5
    I use geolocation to pre-center a google map closer to where the user actually is. Makes the application more intuitive and easier to use. What's the big deal? Jan 12, 2012 at 17:11
  • 2
    Geolocation always picks my home as being in a place about 100 miles from where I actually live. And when I go to websites that use it from work they all think I'm in New York when I'm actually in London. It's worse than useless in my case.
    – jcoder
    Sep 7, 2012 at 9:44
  • 1
    @snurre, anyone committing fraud is likely to use a proxy or VPN anyway, so you're not accomplishing much there.
    – nilskp
    Jul 22, 2013 at 2:16
  • 1
    How about showing pricing in a person's local currency? Local phone number? When visiting "google.com" from within France, you're automatically redirected to "google.fr". All legitimate reasons. Aug 6, 2015 at 2:04

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.