情景1:
查詢ip是否在同一個C段(192.168.10.2-192.168.10.100)
SELECT FROM ip_cz where ip BETWEEN '192.168.10.2' AND '192.168.10.100';
情景2:
查詢ip是否在多個C段(192.168.10.0-192.168.66.0)
SELECT FROM ip_cz where ip BETWEEN INET_ATON(192.168.10.0
) AND INET_ATON(192.168.66.0
);python
ip:想要查找的ip對應的十進制數mysql
start:網段開始地址sql
end:網段結束地址ide
INET_ATON:mysql中將ip轉化爲十進制數的函數函數
python 將ip轉化爲十進制數:code
def ip_change(ip):ip
items = [int(x)for xin ip.split(".")]it
return sum([items[i] << [24, 16, 8, 0][i]for iin range(4)])class