我有maxmind的IPv6数据。这是我的当前表格(带有示例数据):
+---------------+------------+
| network | geoname_id |
+---------------+------------+
| 2001:208::/32 | 123 |
| 2001:218::/32 | 4312 |
+---------------+------------+
使用他们的转换器,我可以创建
network_start_ip
和network_last_ip
列:+------------------+----------------------------------------+------------+
| network_start_ip | network_last_ip | geoname_id |
+------------------+----------------------------------------+------------+
| 2001:200:: | 2001:200:ffff:ffff:ffff:ffff:ffff:ffff | 123 |
| 2001:208:: | 2001:208:ffff:ffff:ffff:ffff:ffff:ffff | 4312 |
+------------------+----------------------------------------+------------+
我原本以为这样的方法可以起作用(尽管可能会比其他方法慢):
SELECT b.geoname_id FROM blocks b
WHERE HEX(INET6_ATON('2001:201:ffff:ffff:ffff:ffff:ffff:ffff')) BETWEEN HEX(b.network_start_ip) AND HEX(b.network_last_ip)
那么,我错过了什么?此外,存储IPv6地址(范围)的最佳方法是什么?
谢谢
INET6_ATON('2001:201:ffff:ffff:ffff:ffff:ffff:ffff') BETWEEN INET6_ATON(b.network_start_ip) AND INET6_ATON(b.network_last_ip)
怎么样? - Paul SpiegelWHERE HEX(INET6_ATON('2001:201:ffff:ffff:ffff:ffff:ffff:ffff')) BETWEEN HEX(INET6_ATON(b.network_start_ip)) AND HEX(INET6_ATON(b.network_last_ip))
- Cornwell