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