Php convert ipv6 to number

前端 未结 7 879
醉话见心
醉话见心 2021-01-31 20:53

In Ipv4 we can use ip2long to convert it to number,

How to convert ipv6 compressed to number in PHP?

I tried inet_pton and it\'s not working.

<
相关标签:
7条回答
  • 2021-01-31 21:30

    OK, some revelations from chat with Ben Wong... The REAL issue is optimizing lookups in a DB about a geoIP service.

    The DB layout offered by this geoIP database is too slow to just have plain ol' BETWEEN applied on the start and end, even though the storage is the most economic one you can get.

    The proposal I first outlined in the chat was to fragment the IP address into 4 ints which are compared sequentially, but on second though, that may not be enough, since you're still searching over the entire DB, which is over 1 million rows. I also had an idea about doing matches with subnet masks, but given that some ranges are not within large masks, doing this may, again, not be enough.

    I'll see what I can do, and I'll edit this answer. But I'm posting this in the meantime for anyone else willing to assist in this.

    0 讨论(0)
提交回复
热议问题