Geolocation with IPv6?

前端 未结 8 2011
梦如初夏
梦如初夏 2021-01-31 19:31

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.

Bu

8条回答
  •  梦如初夏
    2021-01-31 20:19

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

提交回复
热议问题