`
lht
  • 浏览: 199648 次
  • 来自: 深圳
社区版块
存档分类
最新评论

PHP判断一个IP是否联通IP

阅读更多

1. 将联通IP段定义成关联数组。起始地址为KEY,结束地址为VALUE。IP段在这里

2. 通过二分法查找关联数组的KEY数组中第一个不大于此IP的KEY的位置$i

3. 从$i开始遍历KEY数组,判断IP是否处于关联数组中

 

<?php
$ips = array(
        '1.24.0.0' => '1.31.255.255',
        '1.56.0.0' => '1.63.255.255',
        '1.188.0.0' => '1.191.255.255',
        '14.204.0.0' => '14.205.255.255',
        '27.8.0.0' => '27.15.255.255',
        '27.36.0.0' => '27.39.255.255',
        '27.40.0.0' => '27.47.255.255',
        '27.50.128.0' => '27.50.255.255',
        '27.54.192.0' => '27.54.255.255',
        '27.98.224.0' => '27.98.255.255',
        '27.106.128.0' => '27.106.191.255',
        '27.115.0.0' => '27.115.127.255',
        '27.131.220.0' => '27.131.223.255',
        '27.192.0.0' => '27.223.255.255',
        '36.32.0.0' => '36.35.255.255',
        '36.248.0.0' => '36.251.255.255',
        '42.4.0.0' => '42.7.255.255',
        '42.48.0.0' => '42.49.255.255',
        '42.51.0.0' => '42.51.255.255',
        '42.52.0.0' => '42.55.255.255',
        '42.56.0.0' => '42.59.255.255',
        '42.63.0.0' => '42.63.255.255',
        '42.84.0.0' => '42.87.255.255',
        '42.176.0.0' => '42.183.255.255',
        '42.224.0.0' => '42.239.255.255',
        '47.153.128.0' => '47.153.191.255',
        '47.154.0.0' => '47.154.255.255',
        '47.200.192.0' => '47.200.255.255',
        '58.16.0.0' => '58.23.255.255',
        '58.24.0.0' => '58.25.255.255',
        '58.30.64.0' => '58.30.127.255',
        '58.30.128.0' => '58.30.255.255',
        '58.31.0.0' => '58.31.63.255',
        '58.31.192.0' => '58.31.255.255',
        '58.68.128.0' => '58.68.143.255',
        '58.68.144.0' => '58.68.151.255',
        '58.83.17.0' => '58.83.17.255',
        '58.116.0.0' => '58.119.255.255',
        '58.128.0.0' => '58.135.255.255',
        '58.144.0.0' => '58.144.255.255',
        '58.240.0.0' => '58.255.255.255',
        '59.108.32.0' => '59.108.63.255',
        '59.108.64.0' => '59.108.127.255',
        '59.109.64.0' => '59.109.79.255',
        '59.109.80.0' => '59.109.83.255',
        '60.0.0.0' => '60.31.255.255',
        '60.63.0.0' => '60.63.255.255',
        '60.194.0.0' => '60.195.255.255',
        '60.204.0.0' => '60.204.255.255',
        '60.206.0.0' => '60.207.255.255',
        '60.208.0.0' => '60.223.255.255',
        '60.255.0.0' => '60.255.255.255',
        '61.4.176.0' => '61.4.191.255',
        '61.28.0.0' => '61.28.127.255',
        '61.48.0.0' => '61.55.255.255',
        '61.133.0.0' => '61.133.127.255',
        '61.134.96.0' => '61.134.127.255',
        '61.134.128.0' => '61.134.255.255',
        '61.135.0.0' => '61.135.255.255',
        '61.136.0.0' => '61.136.127.255',
        '61.137.128.0' => '61.137.255.255',
        '61.138.0.0' => '61.138.127.255',
        '61.138.128.0' => '61.138.191.255',
        '61.139.128.0' => '61.139.191.255',
        '61.148.0.0' => '61.149.255.255',
        '61.156.0.0' => '61.156.255.255',
        '61.158.0.0' => '61.158.255.255',
        '61.159.0.0' => '61.159.63.255',
        '61.161.0.0' => '61.161.63.255',
        '61.161.128.0' => '61.161.255.255',
        '61.162.0.0' => '61.163.255.255',
        '61.167.0.0' => '61.167.255.255',
        '61.168.0.0' => '61.168.255.255',
        '61.176.0.0' => '61.176.255.255',
        '61.179.0.0' => '61.179.255.255',
        '61.180.128.0' => '61.180.255.255',
        '61.181.0.0' => '61.181.255.255',
        '61.182.0.0' => '61.182.255.255',
        '61.189.0.0' => '61.189.127.255',
        '61.233.16.0' => '61.233.31.255',
        '61.234.0.0' => '61.234.255.255',
        '61.237.224.0' => '61.237.239.255',
        '61.240.0.0' => '61.243.255.255',
        '101.16.0.0' => '101.31.255.255',
        '101.64.0.0' => '101.71.255.255',
        '101.72.0.0' => '101.75.255.255',
        '101.200.0.0' => '101.201.255.255',
        '101.204.0.0' => '101.207.255.255',
        '101.232.0.0' => '101.233.255.255',
        '110.6.0.0' => '110.7.255.255',
        '110.16.0.0' => '110.19.255.255',
        '110.52.0.0' => '110.53.255.255',
        '110.72.0.0' => '110.73.255.255',
        '110.172.224.0' => '110.172.255.255',
        '110.228.0.0' => '110.231.255.255',
        '110.236.0.0' => '110.236.255.255',
        '110.240.0.0' => '110.255.255.255',
        '111.67.192.0' => '111.67.207.255',
        '111.68.64.0' => '111.68.95.255',
        '111.85.0.0' => '111.85.255.255',
        '111.160.0.0' => '111.167.255.255',
        '111.192.0.0' => '111.207.255.255',
        '111.208.0.0' => '111.211.255.255',
        '111.228.0.0' => '111.231.255.255',
        '112.64.0.0' => '112.65.255.255',
        '112.80.0.0' => '112.95.255.255',
        '112.96.0.0' => '112.97.255.255',
        '112.109.128.0' => '112.109.255.255',
        '112.111.0.0' => '112.111.255.255',
        '112.122.0.0' => '112.123.255.255',
        '112.132.0.0' => '112.132.255.255',
        '112.192.0.0' => '112.195.255.255',
        '112.224.0.0' => '112.255.255.255',
        '113.0.0.0' => '113.7.255.255',
        '113.8.0.0' => '113.9.255.255',
        '113.18.0.0' => '113.18.255.255',
        '113.31.16.0' => '113.31.31.255',
        '113.31.32.0' => '113.31.47.255',
        '113.56.0.0' => '113.57.255.255',
        '113.58.0.0' => '113.58.255.255',
        '113.59.0.0' => '113.59.127.255',
        '113.194.0.0' => '113.195.255.255',
        '113.200.0.0' => '113.201.255.255',
        '113.204.0.0' => '113.207.255.255',
        '113.209.192.0' => '113.209.195.255',
        '113.209.255.0' => '113.209.255.255',
        '113.213.0.0' => '113.213.127.255',
        '113.224.0.0' => '113.239.255.255',
        '114.28.128.0' => '114.28.255.255',
        '114.54.0.0' => '114.55.255.255',
        '114.60.0.0' => '114.63.255.255',
        '114.66.0.0' => '114.66.3.255',
        '114.110.0.0' => '114.110.15.255',
        '114.110.64.0' => '114.110.127.255',
        '114.111.0.0' => '114.111.31.255',
        '114.112.16.0' => '114.112.17.255',
        '114.112.24.0' => '114.112.31.255',
        '114.112.136.0' => '114.112.143.255',
        '114.112.144.0' => '114.112.159.255',
        '114.112.160.0' => '114.112.191.255',
        '114.112.192.0' => '114.112.199.255',
        '114.113.16.0' => '114.113.31.255',
        '114.113.32.0' => '114.113.63.255',
        '114.113.64.0' => '114.113.127.255',
        '114.113.128.0' => '114.113.135.255',
        '114.113.144.0' => '114.113.159.255',
        '114.113.208.0' => '114.113.209.255',
        '114.132.128.0' => '114.132.255.255',
        '114.208.0.0' => '114.211.255.255',
        '114.240.0.0' => '114.255.255.255',
        '115.35.128.0' => '115.35.255.255',
        '115.46.0.0' => '115.46.255.255',
        '115.48.0.0' => '115.63.255.255',
        '115.85.192.0' => '115.85.255.255',
        '115.100.0.0' => '115.103.255.255',
        '115.172.0.0' => '115.175.255.255',
        '116.2.0.0' => '116.3.255.255',
        '116.60.0.0' => '116.63.255.255',
        '116.70.0.0' => '116.70.63.255',
        '116.90.80.0' => '116.90.87.255',
        '116.90.184.0' => '116.90.191.255',
        '116.95.0.0' => '116.95.255.255',
        '116.112.0.0' => '116.115.255.255',
        '116.116.0.0' => '116.117.255.255',
        '116.128.0.0' => '116.128.31.255',
        '116.193.16.0' => '116.193.17.255',
        '116.193.18.0' => '116.193.18.255',
        '116.194.0.0' => '116.195.255.255',
        '116.199.0.0' => '116.199.127.255',
        '116.199.128.0' => '116.199.159.255',
        '116.213.128.0' => '116.213.159.255',
        '116.214.32.0' => '116.214.63.255',
        '116.216.0.0' => '116.219.255.255',
        '116.242.0.0' => '116.243.255.255',
        '116.244.0.0' => '116.245.255.255',
        '116.254.128.0' => '116.254.255.255',
        '116.255.128.0' => '116.255.255.255',
        '117.8.0.0' => '117.15.255.255',
        '117.74.64.0' => '117.74.79.255',
        '117.75.0.0' => '117.75.255.255',
        '117.76.0.0' => '117.79.255.255',
        '117.100.0.0' => '117.101.255.255',
        '117.106.0.0' => '117.107.255.255',
        '117.112.0.0' => '117.119.255.255',
        '117.120.64.0' => '117.120.127.255',
        '117.121.0.0' => '117.121.127.255',
        '117.121.128.0' => '117.121.191.255',
        '118.24.0.0' => '118.25.255.255',
        '118.26.16.0' => '118.26.31.255',
        '118.26.128.0' => '118.26.191.255',
        '118.72.0.0' => '118.79.255.255',
        '118.80.0.0' => '118.81.255.255',
        '118.88.32.0' => '118.88.63.255',
        '118.88.64.0' => '118.88.127.255',
        '118.88.128.0' => '118.88.255.255',
        '118.102.16.0' => '118.102.31.255',
        '118.132.0.0' => '118.135.255.255',
        '118.144.128.0' => '118.144.191.255',
        '118.185.0.0' => '118.185.255.255',
        '118.193.240.0' => '118.193.247.255',
        '118.194.128.0' => '118.194.135.255',
        '118.194.192.0' => '118.194.207.255',
        '118.194.232.0' => '118.194.239.255',
        '118.212.0.0' => '118.212.255.255',
        '118.224.0.0' => '118.227.255.255',
        '118.244.0.0' => '118.247.255.255',
        '119.4.0.0' => '119.7.255.255',
        '119.19.0.0' => '119.19.1.255',
        '119.32.0.0' => '119.35.255.255',
        '119.36.0.0' => '119.36.255.255',
        '119.37.0.0' => '119.37.127.255',
        '119.37.128.0' => '119.37.191.255',
        '119.38.0.0' => '119.38.127.255',
        '119.38.128.0' => '119.38.191.255',
        '119.39.0.0' => '119.39.255.255',
        '119.40.0.0' => '119.40.63.255',
        '119.40.128.0' => '119.40.255.255',
        '119.42.0.0' => '119.42.31.255',
        '119.42.224.0' => '119.42.255.255',
        '119.48.0.0' => '119.55.255.255',
        '119.57.0.0' => '119.57.63.255',
        '119.57.64.0' => '119.57.79.255',
        '119.59.128.0' => '119.59.255.255',
        '119.62.0.0' => '119.62.255.255',
        '119.63.32.0' => '119.63.63.255',
        '119.80.32.0' => '119.80.47.255',
        '119.80.56.0' => '119.80.63.255',
        '119.80.64.0' => '119.80.127.255',
        '119.80.128.0' => '119.80.159.255',
        '119.81.0.0' => '119.81.255.255',
        '119.88.0.0' => '119.88.127.255',
        '119.108.0.0' => '119.109.255.255',
        '119.112.0.0' => '119.119.255.255',
        '119.148.160.0' => '119.148.175.255',
        '119.161.128.0' => '119.161.191.255',
        '119.161.208.0' => '119.161.223.255',
        '119.161.224.0' => '119.161.255.255',
        '119.162.0.0' => '119.163.255.255',
        '119.164.0.0' => '119.167.255.255',
        '119.176.0.0' => '119.191.255.255',
        '119.232.0.0' => '119.233.255.255',
        '119.248.0.0' => '119.251.255.255',
        '119.253.32.0' => '119.253.63.255',
        '119.253.128.0' => '119.253.255.255',
        '119.255.0.0' => '119.255.63.255',
        '120.0.0.0' => '120.15.255.255',
        '120.31.0.0' => '120.31.255.255',
        '120.65.0.0' => '120.65.255.255',
        '120.66.0.0' => '120.66.255.255',
        '120.67.128.0' => '120.67.255.255',
        '120.80.0.0' => '120.87.255.255',
        '120.92.0.0' => '120.92.255.255',
        '120.128.0.0' => '120.131.255.255',
        '120.195.0.0' => '120.195.31.255',
        '120.195.32.0' => '120.195.47.255',
        '121.5.0.0' => '121.5.0.255',
        '121.5.16.0' => '121.5.23.255',
        '121.5.32.0' => '121.5.47.255',
        '121.16.0.0' => '121.31.255.255',
        '121.40.0.0' => '121.43.255.255',
        '121.51.0.0' => '121.51.255.255',
        '121.52.208.0' => '121.52.223.255',
        '121.52.224.0' => '121.52.255.255',
        '121.55.0.0' => '121.55.63.255',
        '121.68.0.0' => '121.71.255.255',
        '121.76.0.0' => '121.77.255.255',
        '121.79.128.0' => '121.79.143.255',
        '121.79.144.0' => '121.79.147.255',
        '121.89.0.0' => '121.89.255.255',
        '121.100.128.0' => '121.100.255.255',
        '121.101.208.0' => '121.101.223.255',
        '121.196.0.0' => '121.199.255.255',
        '122.0.64.0' => '122.0.127.255',
        '122.0.128.0' => '122.0.255.255',
        '122.10.228.0' => '122.10.231.255',
        '122.10.232.0' => '122.10.239.255',
        '122.10.240.0' => '122.10.243.255',
        '122.11.40.0' => '122.11.47.255',
        '122.11.48.0' => '122.11.63.255',
        '122.15.0.0' => '122.15.255.255',
        '122.49.0.0' => '122.49.63.255',
        '122.96.0.0' => '122.97.255.255',
        '122.102.0.0' => '122.102.15.255',
        '122.102.64.0' => '122.102.79.255',
        '122.112.0.0' => '122.112.31.255',
        '122.112.128.0' => '122.112.255.255',
        '122.113.0.0' => '122.113.63.255',
        '122.136.0.0' => '122.143.255.255',
        '122.156.0.0' => '122.159.255.255',
        '122.188.0.0' => '122.191.255.255',
        '122.192.0.0' => '122.195.255.255',
        '122.200.64.0' => '122.200.127.255',
        '122.248.48.0' => '122.248.63.255',
        '123.4.0.0' => '123.7.255.255',
        '123.8.0.0' => '123.15.255.255',
        '123.56.0.0' => '123.57.255.255',
        '123.80.0.0' => '123.80.255.255',
        '123.103.2.0' => '123.103.3.255',
        '123.103.4.0' => '123.103.7.255',
        '123.103.8.0' => '123.103.15.255',
        '123.103.16.0' => '123.103.31.255',
        '123.103.32.0' => '123.103.47.255',
        '123.108.208.0' => '123.108.211.255',
        '123.108.212.0' => '123.108.213.255',
        '123.108.216.0' => '123.108.217.255',
        '123.108.220.0' => '123.108.223.255',
        '123.112.0.0' => '123.127.255.255',
        '123.128.0.0' => '123.135.255.255',
        '123.138.0.0' => '123.139.255.255',
        '123.144.0.0' => '123.147.255.255',
        '123.148.0.0' => '123.148.255.255',
        '123.152.0.0' => '123.159.255.255',
        '123.176.80.0' => '123.176.95.255',
        '123.188.0.0' => '123.191.255.255',
        '123.196.0.0' => '123.197.255.255',
        '123.232.0.0' => '123.235.255.255',
        '123.253.0.0' => '123.253.255.255',
        '124.14.160.0' => '124.14.191.255',
        '124.16.248.0' => '124.16.255.255',
        '124.21.0.0' => '124.21.255.255',
        '124.42.0.0' => '124.42.127.255',
        '124.64.0.0' => '124.65.255.255',
        '124.66.0.0' => '124.66.127.255',
        '124.67.0.0' => '124.67.255.255',
        '124.68.0.0' => '124.71.255.255',
        '124.88.0.0' => '124.95.255.255',
        '124.128.0.0' => '124.135.255.255',
        '124.152.0.0' => '124.152.255.255',
        '124.160.0.0' => '124.167.255.255',
        '124.172.0.0' => '124.173.255.255',
        '124.192.0.0' => '124.193.255.255',
        '124.200.0.0' => '124.207.255.255',
        '124.240.128.0' => '124.240.191.255',
        '124.248.32.0' => '124.248.63.255',
        '124.249.0.0' => '124.249.127.255',
        '125.32.0.0' => '125.47.255.255',
        '125.97.240.0' => '125.97.255.255',
        '125.211.0.0' => '125.211.255.255',
        '125.215.0.0' => '125.215.63.255',
        '135.244.80.0' => '135.244.95.255',
        '138.32.244.0' => '138.32.247.255',
        '139.208.0.0' => '139.215.255.255',
        '144.211.80.0' => '144.211.80.255',
        '144.211.138.0' => '144.211.138.255',
        '161.207.0.0' => '161.207.255.255',
        '168.160.224.0' => '168.160.255.255',
        '171.34.0.0' => '171.35.255.255',
        '171.36.0.0' => '171.39.255.255',
        '171.116.0.0' => '171.119.255.255',
        '171.120.0.0' => '171.127.255.255',
        '175.16.0.0' => '175.23.255.255',
        '175.24.0.0' => '175.27.255.255',
        '175.42.0.0' => '175.43.255.255',
        '175.44.0.0' => '175.44.255.255',
        '175.106.128.0' => '175.106.255.255',
        '175.146.0.0' => '175.147.255.255',
        '175.148.0.0' => '175.151.255.255',
        '175.152.0.0' => '175.155.255.255',
        '175.160.0.0' => '175.175.255.255',
        '175.184.128.0' => '175.184.191.255',
        '180.78.0.0' => '180.78.63.255',
        '180.89.128.0' => '180.89.135.255',
        '180.95.128.0' => '180.95.255.255',
        '180.129.128.0' => '180.129.255.255',
        '180.130.0.0' => '180.130.255.255',
        '180.184.0.0' => '180.185.255.255',
        '180.186.0.0' => '180.186.255.255',
        '180.188.0.0' => '180.188.127.255',
        '180.189.148.0' => '180.189.151.255',
        '180.223.0.0' => '180.223.255.255',
        '182.18.0.0' => '182.18.31.255',
        '182.48.96.0' => '182.48.111.255',
        '182.48.112.0' => '182.48.119.255',
        '182.50.4.0' => '182.50.7.255',
        '182.50.112.0' => '182.50.119.255',
        '182.50.120.0' => '182.50.123.255',
        '182.50.124.0' => '182.50.125.255',
        '182.54.0.0' => '182.54.127.255',
        '182.61.128.0' => '182.61.131.255',
        '182.61.192.0' => '182.61.195.255',
        '182.88.0.0' => '182.91.255.255',
        '182.112.0.0' => '182.127.255.255',
        '182.236.128.0' => '182.236.255.255',
        '183.92.0.0' => '183.95.255.255',
        '183.184.0.0' => '183.191.255.255',
        '192.9.202.0' => '192.9.203.255',
        '192.11.23.0' => '192.11.23.255',
        '192.11.26.0' => '192.11.26.255',
        '192.11.39.0' => '192.11.39.255',
        '192.11.236.0' => '192.11.236.255',
        '192.139.135.0' => '192.139.135.255',
        '192.139.136.0' => '192.139.136.255',
        '192.170.79.0' => '192.170.79.255',
        '194.138.202.0' => '194.138.202.255',
        '202.4.252.0' => '202.4.255.255',
        '202.38.8.0' => '202.38.15.255',
        '202.38.147.0' => '202.38.147.255',
        '202.38.161.0' => '202.38.161.255',
        '202.38.164.0' => '202.38.167.255',
        '202.43.144.0' => '202.43.159.255',
        '202.69.4.0' => '202.69.5.255',
        '202.74.8.0' => '202.74.15.255',
        '202.75.208.0' => '202.75.223.255',
        '202.77.39.0' => '202.77.39.255',
        '202.84.16.0' => '202.84.16.255',
        '202.85.208.0' => '202.85.211.255',
        '202.85.216.0' => '202.85.216.255',
        '202.91.176.0' => '202.91.183.255',
        '202.91.184.0' => '202.91.185.255',
        '202.91.186.0' => '202.91.186.255',
        '202.91.190.0' => '202.91.191.255',
        '202.91.224.0' => '202.91.239.255',
        '202.93.252.0' => '202.93.255.255',
        '202.94.1.0' => '202.94.1.255',
        '202.95.0.0' => '202.95.31.255',
        '202.96.0.0' => '202.96.63.255',
        '202.96.64.0' => '202.96.95.255',
        '202.97.128.0' => '202.97.255.255',
        '202.98.0.0' => '202.98.31.255',
        '202.99.0.0' => '202.99.255.255',
        '202.102.128.0' => '202.102.191.255',
        '202.102.224.0' => '202.102.255.255',
        '202.106.0.0' => '202.106.255.255',
        '202.107.0.0' => '202.107.127.255',
        '202.108.0.0' => '202.108.255.255',
        '202.110.0.0' => '202.110.127.255',
        '202.110.192.0' => '202.110.255.255',
        '202.111.128.0' => '202.111.191.255',
        '202.122.128.0' => '202.122.128.255',
        '202.127.40.0' => '202.127.47.255',
        '202.127.48.0' => '202.127.49.255',
        '202.127.112.0' => '202.127.127.255',
        '202.127.208.0' => '202.127.209.255',
        '202.130.224.0' => '202.130.255.255',
        '202.136.254.0' => '202.136.255.255',
        '202.142.16.0' => '202.142.31.255',
        '202.165.208.0' => '202.165.223.255',
        '202.180.128.0' => '202.180.159.255',
        '203.65.240.0' => '203.65.243.255',
        '203.80.144.0' => '203.80.159.255',
        '203.83.56.0' => '203.83.63.255',
        '203.92.160.0' => '203.92.191.255',
        '203.93.0.0' => '203.93.0.255',
        '203.93.8.0' => '203.93.8.255',
        '203.93.18.0' => '203.93.18.255',
        '203.93.27.0' => '203.93.27.255',
        '203.93.28.0' => '203.93.29.255',
        '203.93.64.0' => '203.93.127.255',
        '203.93.192.0' => '203.93.255.255',
        '203.95.0.0' => '203.95.7.255',
        '203.95.104.0' => '203.95.111.255',
        '203.100.192.0' => '203.100.207.255',
        '203.166.160.0' => '203.166.191.255',
        '203.196.5.0' => '203.196.5.255',
        '203.196.6.0' => '203.196.6.255',
        '203.208.0.0' => '203.208.15.255',
        '203.212.0.0' => '203.212.7.255',
        '203.212.8.0' => '203.212.11.255',
        '210.2.24.0' => '210.2.31.255',
        '210.5.128.0' => '210.5.143.255',
        '210.12.155.0' => '210.12.155.255',
        '210.12.232.0' => '210.12.232.255',
        '210.12.240.0' => '210.12.240.255',
        '210.12.242.0' => '210.12.242.255',
        '210.13.0.0' => '210.13.255.255',
        '210.14.64.0' => '210.14.95.255',
        '210.14.160.0' => '210.14.191.255',
        '210.14.192.0' => '210.14.223.255',
        '210.15.32.0' => '210.15.63.255',
        '210.15.96.0' => '210.15.127.255',
        '210.15.128.0' => '210.15.191.255',
        '210.16.128.0' => '210.16.191.255',
        '210.21.0.0' => '210.21.255.255',
        '210.22.48.0' => '210.22.63.255',
        '210.51.0.0' => '210.51.255.255',
        '210.52.128.0' => '210.52.255.255',
        '210.53.0.0' => '210.53.255.255',
        '210.56.192.0' => '210.56.223.255',
        '210.72.160.0' => '210.72.191.255',
        '210.72.192.0' => '210.72.223.255',
        '210.73.0.0' => '210.73.15.255',
        '210.73.112.0' => '210.73.127.255',
        '210.73.160.0' => '210.73.191.255',
        '210.73.224.0' => '210.73.255.255',
        '210.74.0.0' => '210.74.31.255',
        '210.74.64.0' => '210.74.65.255',
        '210.74.96.0' => '210.74.127.255',
        '210.74.128.0' => '210.74.191.255',
        '210.75.160.0' => '210.75.191.255',
        '210.76.32.0' => '210.76.63.255',
        '210.76.96.0' => '210.76.127.255',
        '210.76.192.0' => '210.76.223.255',
        '210.77.0.0' => '210.77.63.255',
        '210.77.176.0' => '210.77.191.255',
        '210.77.192.0' => '210.77.255.255',
        '210.78.0.0' => '210.78.31.255',
        '210.78.128.0' => '210.78.255.255',
        '210.79.224.0' => '210.79.255.255',
        '210.82.0.0' => '210.83.255.255',
        '210.192.96.0' => '210.192.103.255',
        '210.192.112.0' => '210.192.115.255',
        '210.192.120.0' => '210.192.127.255',
        '211.90.0.0' => '211.91.255.255',
        '211.92.0.0' => '211.95.255.255',
        '211.96.0.0' => '211.97.255.255',
        '211.99.32.0' => '211.99.63.255',
        '211.99.64.0' => '211.99.95.255',
        '211.99.224.0' => '211.99.255.255',
        '211.100.192.0' => '211.100.207.255',
        '211.100.224.0' => '211.100.255.255',
        '211.101.128.0' => '211.101.255.255',
        '211.102.128.0' => '211.102.191.255',
        '211.103.128.0' => '211.103.255.255',
        '211.144.0.0' => '211.145.255.255',
        '211.147.0.0' => '211.147.63.255',
        '211.147.160.0' => '211.147.191.255',
        '211.150.64.0' => '211.150.95.255',
        '211.152.0.0' => '211.159.255.255',
        '211.162.0.0' => '211.162.31.255',
        '211.162.104.0' => '211.162.105.255',
        '211.162.200.0' => '211.162.203.255',
        '211.167.96.0' => '211.167.127.255',
        '211.167.176.0' => '211.167.191.255',
        '211.167.224.0' => '211.167.255.255',
        '218.7.0.0' => '218.7.255.255',
        '218.8.0.0' => '218.11.255.255',
        '218.12.0.0' => '218.12.255.255',
        '218.21.128.0' => '218.21.255.255',
        '218.24.0.0' => '218.27.255.255',
        '218.28.0.0' => '218.29.255.255',
        '218.30.223.0' => '218.30.223.255',
        '218.30.254.0' => '218.30.254.255',
        '218.56.0.0' => '218.59.255.255',
        '218.60.0.0' => '218.61.255.255',
        '218.62.0.0' => '218.62.127.255',
        '218.67.128.0' => '218.67.255.255',
        '218.68.0.0' => '218.69.255.255',
        '218.104.0.0' => '218.107.255.255',
        '218.240.0.0' => '218.240.63.255',
        '218.241.0.0' => '218.241.31.255',
        '218.241.64.0' => '218.241.95.255',
        '218.241.128.0' => '218.241.255.255',
        '218.242.0.0' => '218.242.255.255',
        '218.246.96.0' => '218.246.127.255',
        '218.246.224.0' => '218.246.239.255',
        '218.247.32.0' => '218.247.63.255',
        '218.247.128.0' => '218.247.255.255',
        '218.249.0.0' => '218.249.63.255',
        '219.154.0.0' => '219.155.255.255',
        '219.156.0.0' => '219.157.255.255',
        '219.158.0.0' => '219.158.255.255',
        '219.159.0.0' => '219.159.63.255',
        '219.232.0.0' => '219.235.255.255',
        '219.238.128.0' => '219.238.191.255',
        '219.239.0.0' => '219.239.63.255',
        '220.112.0.0' => '220.115.255.255',
        '220.152.128.0' => '220.152.255.255',
        '220.192.0.0' => '220.207.255.255',
        '220.231.0.0' => '220.231.63.255',
        '220.234.0.0' => '220.234.255.255',
        '220.242.0.0' => '220.243.255.255',
        '220.248.0.0' => '220.251.255.255',
        '220.252.0.0' => '220.252.255.255',
        '221.0.0.0' => '221.7.255.255',
        '221.8.0.0' => '221.11.255.255',
        '221.12.0.0' => '221.12.127.255',
        '221.12.128.0' => '221.12.191.255',
        '221.13.0.0' => '221.13.255.255',
        '221.14.0.0' => '221.15.255.255',
        '221.122.0.0' => '221.122.255.255',
        '221.123.128.0' => '221.123.255.255',
        '221.133.240.0' => '221.133.255.255',
        '221.137.0.0' => '221.137.255.255',
        '221.192.0.0' => '221.195.255.255',
        '221.196.0.0' => '221.197.255.255',
        '221.198.0.0' => '221.198.255.255',
        '221.199.0.0' => '221.199.127.255',
        '221.199.128.0' => '221.199.191.255',
        '221.199.192.0' => '221.199.207.255',
        '221.199.224.0' => '221.199.255.255',
        '221.200.0.0' => '221.207.255.255',
        '221.208.0.0' => '221.223.255.255',
        '222.34.0.0' => '222.34.255.255',
        '222.35.0.0' => '222.35.127.255',
        '222.60.0.0' => '222.60.255.255',
        '222.128.0.0' => '222.143.255.255',
        '222.160.0.0' => '222.163.255.255',
        '222.249.0.0' => '222.249.255.255',
        '223.27.184.0' => '223.27.187.255',
        '223.166.0.0' => '223.167.255.255',
        '223.202.0.0' => '223.202.127.255',
        '223.254.0.0' => '223.254.255.255',
        '223.255.0.0' => '223.255.127.255',
);

$ipk = array_keys($ips);

function ip_cmp($a, $b)
{
        $a = ip2long($a);
        if ($a < 0) $a += 4294967296;
        $b = ip2long($b);
        if ($b < 0) $b += 4294967296;
        return $a - $b;
}

function binary_search_low($a, $v)
{
        $ret = $low = 0;
        $high = count($a) - 1;
        while ($low <= $high) {
                $mid = intval(($low+$high)/2);
                $cmp = ip_cmp($a[$mid], $v);
                if ($cmp == 0) return $mid;
                else if ($cmp < 0) $low = $mid + 1;
                else $high = $mid - 1;
        }
        $ret = min($low, $mid, $high);
        return $ret;
}

function is_cuc($ip)
{
        global $ips, $ipk;
        $n = count($ipk);
        for($i = binary_search_low($ipk, $ip); $i < $n && ip_cmp($ipk[$i], $ip) <= 0; $i++) {
                if (ip_cmp($ip, $ips[$ipk[$i]]) <= 0) return true;
        }
        return false;
}

function test()
{
        global $ips;

        foreach($ips as $k => $v) {
                if (!is_cuc($k)) die('bad ip:'.$k."\n");
                if (!is_cuc($v)) die('bad ip:'.$v."\n");
        }
        if (is_cuc("58.60.37.0")) die("wrong 58.60.37.0");
        if (is_cuc("218.206.191.0")) die("wrong 218.206.191.0");
}

test();

分享到:
评论

相关推荐

    Ip2region (2.0 - xdb) 是一个离线 IP 数据管理框架和定位库

    Ip2region (2.0 - xdb) 是一个强大的离线IP数据管理工具,专为高效、快速地处理大规模IP地址段而设计。这个框架的核心是它的xdb数据库格式,能够提供亿级别IP数据的存储和检索能力,同时保证了极低的查询延迟,通常...

    PHP 根据IP地址获取所在城市

    本文将详细解析一个PHP脚本如何通过IP地址来获取用户的所在城市,并进一步探讨该脚本的工作原理、关键函数的作用以及可能存在的问题。 #### 1. 获取客户端IP地址 首先,我们需要获取客户端的IP地址。这部分代码...

    纯真IP数据库(可在线更新加入最新的IP地址)

    希望能够通过大家的共同努力打造一个没有未知数据,没有错误数据的QQ IP。IP数据库每 5天更新一次,请大家定期更新最新的IP数据库! 在线升级数据库: 随数据库附送的查询程序(Showip.exe)具有在线检测并升级IP...

    解析ip库跳转

    IP库,又称为IP地址数据库,是一个存储大量IP地址及其对应地理位置、网络运营商等信息的数据库。这些数据通常由ISP(Internet Service Provider,互联网服务提供商)提供,用于帮助企业或个人识别网络流量来源,进行...

    IP地址域名查询程序 1.0.rar

    IP地址域名查询程序所用IP数据库为纯真IP数据库,是本地数据库,绝非小偷程序,使用...希望能够通过大家的共同努力打造一个没有未知数据,没有错误数据的QQ IP。IP数据库每5天更新一次,请大家定期更新最新的IP数据库!

    ip2region是离线IP地址定位库和IP定位数据管理框架

    `ip2region`是一个高效且灵活的IP地址定位库,特别适用于那些需要在没有网络连接的环境下进行IP地址归属地查询的应用。它是一个纯内存数据库,设计目标是提供快速、准确的IP到地区映射服务,无需依赖外部API或在线...

    淘宝IP地址库,提供API

    淘宝IP地址库与API服务详解 一、淘宝IP地址库简介 淘宝IP地址库是阿里巴巴集团为满足广大开发者对IP地址解析的需求而推出的在线服务。...对于需要处理大量网络数据的项目来说,淘宝IP地址库无疑是一个值得信赖的选择。

    PHP实例开发源码—ip手机号码地址查询 php版.zip

    该压缩包文件“PHP实例开发源码—ip手机号码地址查询 php版.zip”包含了一个基于PHP的IP和手机号码地理位置查询的源代码实现。在这个项目中,开发者可能使用了公开的API或者数据库来获取IP地址和手机号码对应的位置...

    B114NET-IP查询系统.rar

    4. **IP状态**:系统可能显示IP是否在线、是否被封锁或者是否属于开放代理等状态,这对于网络安全和防止DDoS攻击至关重要。 5. **IP段信息**:对于IP段查询,系统可能包含CIDR(无类别域间路由)块的解析,以及子网...

    纯真IP数据库 文本版 解压即可用

    IP数据记录:380673条 收集了包括中国电信、中国移动、中国联通、长城宽带、聚友宽带等 ISP 的最新准确 IP 地址数据。解压可用,由于记录较多尽量不要用记事本打开,用功能强大的工具如edplus等...

    qqzeng-ip:最新IP地址数据库-多语言解析以及导入数据库脚本

    -可根据IP获取用户使用线路(电信、联通、移动、教育网、铁通、鹏博士、广电网等) -可根据IP查询到中国(内地、香港、澳门、台湾)所有省市区(县)及运营商ISP信息 -240多个国家和地区 34个省+(香港/澳门/台湾) ...

    php、ip/域名、手机号智能查询V1.0版

    IP数据记录:376330条 数据库大小:6M ...希望能够通过大家的共同努力打造一个没有未知数据,没有错误数据的QQ IP。IP数据库每5天更新一次,请大家定期更新最新的IP数据库! 最新版本下载:www.ucegg.com

    PHP网络速度测试(含源码)

    此程序的核心在于`speedtest.php`文件,这是一个PHP脚本,实现了网络速度的测量逻辑。通常,这个脚本会包含以下关键组成部分: 1. **数据生成**:为了测试网络速度,脚本可能首先生成一定量的数据,比如创建一个大...

    PHP的三网合一短信网关核心框架,基于Swoole4协程实现高并发,支持(cmpp2(移动)/smpp3(移动)/sgip(联通

    本文将深入探讨一个基于PHP的三网合一短信网关核心框架,该框架利用了Swoole 4协程技术来实现高并发处理,支持多种通信协议,包括cmpp2(移动)、smpp3(移动)、sgip(联通)以及smgp(电信)。 首先,让我们了解...

    中国联通营业厅手机卡上网用户登记系统综合课设报告.pdf

    1. 文件标题与描述显示,文档可能是一个关于“中国联通营业厅手机卡上网用户登记系统”的综合课设报告。这意味着该报告可能是针对中国联通营业厅设计的手机卡上网用户信息管理系统的课程设计成果。该系统主要目的是...

    php免费短信接口程序源码

    我们需要解析这个响应,判断短信发送是否成功,并处理可能出现的异常情况。 5. **日志记录**:为了便于后期跟踪和故障排查,通常会在代码中加入日志记录功能,记录每次发送请求的详细信息,包括请求内容、响应结果...

    php 2018最新手机号归属地查询源码,完整版

    标题中的"php 2018最新手机号归属地查询源码,完整版"指的是一个基于PHP编程语言的源代码,该源代码专用于查询手机号码的归属地信息。这个源码是2018年的最新版本,意味着它可能包含了当时最新的技术和数据资源,以...

    惜笔全局免流

    但这只是一个设想,因为有许多软件和游戏不走代理,只能使用直连接入,而通过代理点接入,会使用套餐外的流量,也就是你用的免流ip的流量,移动的掌厅好像是15G上限,联通掌厅可以破6G,理论可以无限使用流量,而...

    IMS接入网智能运维系统的应用与实践——以中国联通无锡分公司为例.pdf

    IMS接入网智能运维系统是现代通信网络中一个关键的组成部分,尤其在中国联通无锡分公司的实践中,该系统通过集成先进技术,显著提升了网络维护的效率和安全性。本文主要探讨了IMS接入网面临的问题,以及如何利用...

Global site tag (gtag.js) - Google Analytics