Converting IP to an integer, and then comparing the integer prime. MySQL offers the inet_aton function for this.
select Country from table_name where inet_aton($ip) between inet_aton(`from`) and inet_aton(`ip`);
For performance, you must convert the from , to column to an integer. eg. add from_n , to_n . then your SQL will look like this:
select Country from table_name where inet_aton($ip) between `from_n` and `to_n`
If you are not using MySQL, you must first convert $ip to integer $ ip_n (using something like Python socket.inet_aton ) and then replace inet_aton($ip) with $ip_n .
Xing fei
source share