diff --git a/CIDR.py b/CIDR.py new file mode 100644 index 0000000..1bd4fec --- /dev/null +++ b/CIDR.py @@ -0,0 +1,1523 @@ +#! env pyrhon3 +# encoding: utf-8 + +cidr=[ +"36.128.0.0/10", +"39.128.0.0/10", +"43.239.172.0/22", +"43.251.244.0/22", +"45.121.68.0/22", +"45.121.72.0/22", +"45.121.172.0/22", +"45.121.176.0/22", +"45.122.96.0/21", +"45.123.152.0/22", +"45.124.36.0/22", +"45.125.24.0/22", +"103.20.112.0/22", +"103.21.176.0/22", +"103.35.104.0/22", +"103.61.156.0/22", +"103.61.160.0/22", +"103.62.24.0/22", +"103.62.204.0/22", +"103.62.208.0/22", +"103.192.0.0/22", +"103.192.144.0/22", +"103.193.140.0/22", +"111.0.0.0/10", +"112.0.0.0/10", +"117.128.0.0/10", +"120.192.0.0/10", +"183.192.0.0/10", +"211.103.0.0/17", +"211.136.0.0/14", +"211.140.0.0/15", +"211.142.0.0/17", +"211.142.128.0/17", +"211.143.0.0/16", +"218.200.0.0/14", +"218.204.0.0/15", +"218.206.0.0/15", +"221.130.0.0/15", +"221.176.0.0/13", +"223.64.0.0/11", +"223.96.0.0/12", +"223.112.0.0/14", +"223.116.0.0/15", +"223.120.0.0/13", +"39.108.0.0/16", +"39.108.128.0/17",#alicloud +"42.96.128.0/17", +"42.96.160.0/19", +"42.96.192.0/19", +"42.96.224.0/19", +"42.120.0.0/16", +"42.120.88.0/21", +"42.120.89.0/24", +"42.120.128.0/17", +"42.120.220.0/24", +"42.120.221.0/24", +"42.120.232.0/23", +"42.120.248.0/24", +"42.120.250.0/24", +"42.121.0.0/16", +"42.121.128.0/17", +"42.156.128.0/17", +"42.156.192.0/18", +"42.156.207.0/24", +"42.156.228.0/24", +"45.113.40.0/22", +"45.113.42.0/23", +"47.92.0.0/14", +"47.94.0.0/15", +"59.110.0.0/16", +"59.110.128.0/17", +"60.205.0.0/16", +"60.205.128.0/17", +"101.37.0.0/16", +"101.37.128.0/17", +"101.200.0.0/15", +"101.201.0.0/16", +"103.52.196.0/22", +"103.52.198.0/23", +"106.11.0.0/16", +"106.11.1.0/24", +"106.11.32.0/22", +"106.11.36.0/22", +"106.11.40.0/21", +"106.11.48.0/21", +"106.11.56.0/21", +"106.11.64.0/19", +"106.11.128.0/20", +"106.11.144.0/20", +"106.11.160.0/20", +"106.11.176.0/21", +"106.11.184.0/21", +"106.11.192.0/23", +"106.11.194.0/23", +"106.11.196.0/23", +"106.11.198.0/24", +"106.11.199.0/24", +"106.11.200.0/24", +"106.11.208.0/21", +"106.14.0.0/15", +"106.15.0.0/16", +"110.75.0.0/16", +"110.75.44.0/23", +"110.75.46.0/23", +"110.75.48.0/23", +"110.75.72.0/24", +"110.75.73.0/24", +"110.75.123.0/24", +"110.75.124.0/24", +"110.75.128.0/17", +"110.75.138.0/23", +"110.75.158.0/24", +"110.75.227.0/24", +"110.75.228.0/24", +"110.75.233.0/24", +"110.75.236.0/22", +"110.75.240.0/20", +"110.76.0.0/19", +"110.76.16.0/20", +"110.76.21.0/24", +"110.76.23.0/24", +"110.76.30.0/23", +"110.76.32.0/20", +"110.76.48.0/20", +"110.76.56.0/22", +"110.76.60.0/22", +"110.173.192.0/19", +"110.173.196.0/24", +"110.173.208.0/20", +"112.74.0.0/16", +"112.74.128.0/17", +"112.124.0.0/16", +"112.124.128.0/17", +"112.124.156.0/23", +"112.124.209.0/24", +"112.124.210.0/24", +"112.125.0.0/16", +"112.125.128.0/17", +"112.126.0.0/16", +"112.126.128.0/17", +"112.127.0.0/16", +"112.127.128.0/17", +"114.55.0.0/16", +"114.55.128.0/17", +"114.215.0.0/16", +"114.215.64.0/18", +"114.215.96.0/19", +"114.215.128.0/19", +"114.215.160.0/21", +"114.215.164.0/22", +"115.28.0.0/16", +"115.28.64.0/18", +"115.28.128.0/18", +"115.28.192.0/18", +"115.29.0.0/16", +"115.29.32.0/19", +"115.29.64.0/18", +"115.29.128.0/17", +"115.124.16.0/20", +"115.124.18.0/24", +"115.124.19.0/24", +"115.124.20.0/22", +"115.124.24.0/21", +"116.62.0.0/16", +"116.62.128.0/17", +"118.178.0.0/16", +"118.178.128.0/17", +"118.190.0.0/16", +"118.190.128.0/17", +"119.23.0.0/16", +"119.23.128.0/17", +"119.38.208.0/20", +"119.38.216.0/21", +"119.38.219.0/24", +"119.42.224.0/19", +"119.42.242.0/23", +"119.42.244.0/22", +"119.42.248.0/21", +"120.24.0.0/14", +"120.25.0.0/16", +"120.26.0.0/16", +"120.27.0.0/17", +"120.27.64.0/18", +"120.27.128.0/17", +"120.27.192.0/18", +"120.55.0.0/16", +"120.55.128.0/17", +"120.76.0.0/15", +"120.76.128.0/17", +"120.77.0.0/16", +"120.77.128.0/17", +"120.78.0.0/15", +"121.0.16.0/20", +"121.0.24.0/22", +"121.0.28.0/22", +"121.40.0.0/14", +"121.42.0.0/15", +"121.42.17.0/24", +"121.42.64.0/18", +"121.42.128.0/18", +"121.42.192.0/19", +"121.42.224.0/19", +"121.196.0.0/14", +"121.197.0.0/16", +"121.198.0.0/16", +"121.199.0.0/16", +"123.56.0.0/15", +"123.57.0.0/16", +"139.129.0.0/16", +"139.129.128.0/17", +"139.196.0.0/16", +"139.196.128.0/17", +"139.224.0.0/16", +"139.224.128.0/17", +"140.205.0.0/16", +"140.205.32.0/19", +"140.205.76.0/24", +"140.205.128.0/18", +"140.205.192.0/18", +"182.92.0.0/16", +"182.92.128.0/17", +"203.107.0.0/24", +"203.107.1.0/24", +"203.209.224.0/19", +"203.209.226.0/23", +"203.209.228.0/22", +"203.209.232.0/21", +"203.209.240.0/20", +"218.244.128.0/19", +"218.244.144.0/20", +"223.4.0.0/14", +"223.5.0.0/16", +"223.5.5.0/24", +"223.6.0.0/16", +"223.6.6.0/24", +"43.242.252.0/22", +"43.247.196.0/22", +"58.87.64.0/18", +"58.87.106.0/23", +"58.87.108.0/23", +"58.87.110.0/23", +"58.87.112.0/23", +"58.87.114.0/23", +"58.87.116.0/23", +"58.87.118.0/23", +"58.87.120.0/23", +"58.87.122.0/23", +"58.87.124.0/23", +"58.87.126.0/23", +"103.38.116.0/22", +"103.238.16.0/22", +"111.230.0.0/23", +"111.230.0.0/15", +"111.230.2.0/23", +"111.230.4.0/23", +"111.230.6.0/23", +"111.230.8.0/23", +"111.230.10.0/23", +"111.230.12.0/23", +"111.230.14.0/23", +"111.230.16.0/23", +"111.230.18.0/23", +"111.230.20.0/23", +"111.230.22.0/23", +"111.230.24.0/23", +"111.230.26.0/23", +"111.230.28.0/23", +"111.230.30.0/23", +"111.230.32.0/23", +"111.230.34.0/23", +"111.230.36.0/23", +"111.230.38.0/23", +"111.230.40.0/23", +"111.230.42.0/23", +"111.230.44.0/23", +"111.230.46.0/23", +"111.230.48.0/23", +"111.230.50.0/23", +"111.230.52.0/23", +"111.230.54.0/23", +"111.230.56.0/23", +"111.230.58.0/23", +"111.230.60.0/23", +"111.230.62.0/23", +"111.230.64.0/23", +"111.230.66.0/23", +"111.230.68.0/23", +"111.230.70.0/23", +"111.230.72.0/23", +"111.230.74.0/23", +"111.230.76.0/23", +"111.230.78.0/23", +"111.230.80.0/23", +"111.230.82.0/23", +"111.230.84.0/23", +"111.230.86.0/23", +"111.230.88.0/23", +"111.230.90.0/23", +"111.230.92.0/23", +"111.230.94.0/23", +"111.230.96.0/23", +"111.230.98.0/23", +"111.230.100.0/23", +"111.230.102.0/23", +"111.230.104.0/23", +"111.230.106.0/23", +"111.230.108.0/23", +"111.230.110.0/23", +"111.230.112.0/23", +"111.230.114.0/23", +"111.230.116.0/23", +"111.230.118.0/23", +"111.230.120.0/23", +"111.230.122.0/23", +"111.230.124.0/23", +"111.230.126.0/23", +"111.230.128.0/23", +"111.230.130.0/23", +"111.230.132.0/23", +"111.230.134.0/23", +"111.230.136.0/23", +"111.230.138.0/23", +"111.230.140.0/23", +"111.230.142.0/23", +"111.230.144.0/23", +"111.230.146.0/23", +"111.230.148.0/23", +"111.230.150.0/23", +"111.230.152.0/23", +"111.230.154.0/23", +"111.230.156.0/23", +"111.231.0.0/23", +"111.231.2.0/23", +"111.231.4.0/23", +"111.231.6.0/23", +"111.231.8.0/23", +"111.231.10.0/23", +"111.231.12.0/23", +"111.231.14.0/23", +"111.231.16.0/23", +"111.231.18.0/23", +"111.231.20.0/23", +"111.231.22.0/23", +"111.231.24.0/23", +"111.231.26.0/23", +"111.231.28.0/23", +"111.231.30.0/23", +"111.231.32.0/23", +"111.231.34.0/23", +"111.231.36.0/23", +"111.231.38.0/23", +"111.231.40.0/23", +"111.231.42.0/23", +"111.231.44.0/23", +"111.231.46.0/23", +"111.231.48.0/23", +"111.231.50.0/23", +"111.231.52.0/22", +"111.231.56.0/22", +"111.231.60.0/22", +"111.231.64.0/22", +"111.231.68.0/22", +"111.231.72.0/22", +"111.231.76.0/22", +"111.231.80.0/22", +"111.231.84.0/22", +"111.231.88.0/22", +"111.231.92.0/22", +"111.231.96.0/22", +"111.231.100.0/22", +"111.231.104.0/22", +"111.231.108.0/22", +"111.231.112.0/22", +"111.231.116.0/22", +"111.231.120.0/22", +"111.231.124.0/22", +"111.231.128.0/22", +"111.231.132.0/22", +"111.231.136.0/22", +"111.231.140.0/22", +"111.231.144.0/22", +"111.231.148.0/22", +"115.159.0.0/23", +"115.159.0.0/16", +"115.159.2.0/23", +"115.159.4.0/23", +"115.159.6.0/23", +"115.159.8.0/23", +"115.159.10.0/23", +"115.159.12.0/23", +"115.159.14.0/23", +"115.159.16.0/23", +"115.159.18.0/23", +"115.159.20.0/23", +"115.159.22.0/23", +"115.159.24.0/23", +"115.159.26.0/23", +"115.159.28.0/23", +"115.159.30.0/23", +"115.159.32.0/23", +"115.159.34.0/23", +"115.159.36.0/23", +"115.159.38.0/23", +"115.159.40.0/23", +"115.159.42.0/23", +"115.159.44.0/23", +"115.159.46.0/23", +"115.159.48.0/23", +"115.159.50.0/23", +"115.159.52.0/23", +"115.159.54.0/23", +"115.159.56.0/23", +"115.159.58.0/23", +"115.159.60.0/23", +"115.159.62.0/23", +"115.159.64.0/23", +"115.159.66.0/23", +"115.159.68.0/23", +"115.159.70.0/23", +"115.159.72.0/23", +"115.159.74.0/23", +"115.159.76.0/23", +"115.159.78.0/23", +"115.159.80.0/23", +"115.159.82.0/23", +"115.159.84.0/23", +"115.159.86.0/23", +"115.159.88.0/23", +"115.159.90.0/23", +"115.159.92.0/23", +"115.159.94.0/23", +"115.159.96.0/23", +"115.159.98.0/23", +"115.159.100.0/23", +"115.159.102.0/23", +"115.159.104.0/23", +"115.159.106.0/23", +"115.159.108.0/23", +"115.159.110.0/23", +"115.159.112.0/23", +"115.159.114.0/23", +"115.159.116.0/23", +"115.159.118.0/23", +"115.159.120.0/23", +"115.159.122.0/23", +"115.159.124.0/23", +"115.159.126.0/23", +"115.159.128.0/23", +"115.159.130.0/23", +"115.159.132.0/23", +"115.159.134.0/23", +"115.159.136.0/23", +"115.159.138.0/23", +"115.159.140.0/23", +"115.159.142.0/23", +"115.159.144.0/23", +"115.159.146.0/23", +"115.159.148.0/23", +"115.159.150.0/23", +"115.159.152.0/23", +"115.159.154.0/23", +"115.159.156.0/23", +"115.159.158.0/23", +"115.159.160.0/23", +"115.159.162.0/23", +"115.159.164.0/23", +"115.159.166.0/23", +"115.159.168.0/23", +"115.159.170.0/23", +"115.159.172.0/23", +"115.159.174.0/23", +"115.159.176.0/23", +"115.159.178.0/23", +"115.159.180.0/23", +"115.159.182.0/23", +"115.159.184.0/23", +"115.159.186.0/23", +"115.159.188.0/23", +"115.159.190.0/23", +"115.159.192.0/23", +"115.159.194.0/23", +"115.159.196.0/23", +"115.159.198.0/23", +"115.159.200.0/23", +"115.159.202.0/23", +"115.159.204.0/23", +"115.159.206.0/23", +"115.159.208.0/23", +"115.159.210.0/23", +"115.159.212.0/23", +"115.159.214.0/23", +"115.159.216.0/23", +"115.159.218.0/23", +"115.159.220.0/23", +"115.159.222.0/23", +"115.159.224.0/23", +"115.159.226.0/23", +"115.159.228.0/23", +"115.159.230.0/23", +"115.159.232.0/23", +"115.159.234.0/23", +"115.159.236.0/23", +"115.159.238.0/24", +"115.159.240.0/23", +"115.159.242.0/23", +"115.159.244.0/23", +"115.159.246.0/23", +"115.159.248.0/23", +"115.159.250.0/23", +"115.159.252.0/23", +"115.159.254.0/23", +"118.89.0.0/23", +"118.89.0.0/16", +"118.89.2.0/23", +"118.89.4.0/23", +"118.89.6.0/23", +"118.89.8.0/23", +"118.89.10.0/23", +"118.89.12.0/23", +"118.89.14.0/23", +"118.89.16.0/23", +"118.89.18.0/23", +"118.89.20.0/23", +"118.89.22.0/23", +"118.89.24.0/23", +"118.89.26.0/23", +"118.89.28.0/23", +"118.89.30.0/23", +"118.89.32.0/23", +"118.89.34.0/23", +"118.89.36.0/23", +"118.89.38.0/23", +"118.89.40.0/23", +"118.89.42.0/23", +"118.89.44.0/23", +"118.89.46.0/23", +"118.89.48.0/23", +"118.89.50.0/23", +"118.89.52.0/23", +"118.89.54.0/23", +"118.89.56.0/23", +"118.89.58.0/23", +"118.89.60.0/23", +"118.89.62.0/23", +"118.89.64.0/23", +"118.89.66.0/23", +"118.89.68.0/23", +"118.89.70.0/23", +"118.89.72.0/23", +"118.89.74.0/23", +"118.89.76.0/23", +"118.89.78.0/23", +"118.89.80.0/23", +"118.89.82.0/23", +"118.89.84.0/23", +"118.89.86.0/23", +"118.89.88.0/23", +"118.89.90.0/23", +"118.89.92.0/23", +"118.89.94.0/23", +"118.89.96.0/23", +"118.89.98.0/23", +"118.89.100.0/23", +"118.89.102.0/23", +"118.89.104.0/23", +"118.89.106.0/23", +"118.89.108.0/23", +"118.89.110.0/23", +"118.89.112.0/23", +"118.89.114.0/23", +"118.89.116.0/23", +"118.89.118.0/23", +"118.89.120.0/23", +"118.89.122.0/23", +"118.89.124.0/23", +"118.89.126.0/23", +"118.89.128.0/23", +"118.89.130.0/23", +"118.89.132.0/23", +"118.89.134.0/23", +"118.89.136.0/23", +"118.89.138.0/23", +"118.89.140.0/23", +"118.89.142.0/23", +"118.89.144.0/23", +"118.89.146.0/23", +"118.89.148.0/23", +"118.89.150.0/23", +"118.89.152.0/23", +"118.89.154.0/23", +"118.89.156.0/23", +"118.89.158.0/23", +"118.89.160.0/23", +"118.89.162.0/23", +"118.89.164.0/23", +"118.89.166.0/23", +"118.89.168.0/23", +"118.89.170.0/23", +"118.89.172.0/23", +"118.89.174.0/23", +"118.89.176.0/23", +"118.89.178.0/23", +"118.89.180.0/23", +"118.89.182.0/23", +"118.89.184.0/23", +"118.89.186.0/23", +"118.89.188.0/23", +"118.89.190.0/23", +"118.89.192.0/23", +"118.89.194.0/23", +"118.89.196.0/23", +"118.89.198.0/23", +"118.89.200.0/23", +"118.89.202.0/23", +"118.89.204.0/23", +"118.89.206.0/23", +"118.89.208.0/23", +"118.89.210.0/23", +"118.89.212.0/23", +"118.89.214.0/23", +"118.89.216.0/23", +"118.89.218.0/23", +"118.89.220.0/23", +"118.89.222.0/23", +"118.89.224.0/23", +"118.89.226.0/23", +"118.89.228.0/23", +"118.89.230.0/23", +"118.89.232.0/23", +"118.89.234.0/23", +"118.89.236.0/23", +"118.89.238.0/23", +"118.89.240.0/23", +"118.89.242.0/23", +"118.89.244.0/23", +"118.89.246.0/23", +"118.89.248.0/23", +"118.89.250.0/23", +"118.89.252.0/23", +"118.89.254.0/23", +"118.126.64.0/18", +"119.27.160.0/19", +"119.29.0.0/23", +"119.29.0.0/16", +"119.29.2.0/23", +"119.29.4.0/23", +"119.29.6.0/23", +"119.29.8.0/23", +"119.29.10.0/23", +"119.29.12.0/23", +"119.29.14.0/23", +"119.29.16.0/23", +"119.29.18.0/23", +"119.29.20.0/23", +"119.29.22.0/23", +"119.29.24.0/23", +"119.29.26.0/23", +"119.29.28.0/23", +"119.29.29.0/24", +"119.29.30.0/23", +"119.29.32.0/23", +"119.29.34.0/23", +"119.29.36.0/23", +"119.29.38.0/23", +"119.29.40.0/23", +"119.29.42.0/23", +"119.29.44.0/23", +"119.29.46.0/23", +"119.29.48.0/23", +"119.29.50.0/23", +"119.29.52.0/23", +"119.29.54.0/23", +"119.29.56.0/23", +"119.29.58.0/23", +"119.29.60.0/23", +"119.29.62.0/23", +"119.29.64.0/23", +"119.29.66.0/23", +"119.29.68.0/23", +"119.29.70.0/23", +"119.29.72.0/23", +"119.29.74.0/23", +"119.29.76.0/23", +"119.29.78.0/23", +"119.29.80.0/23", +"119.29.82.0/23", +"119.29.84.0/23", +"119.29.86.0/23", +"119.29.88.0/23", +"119.29.90.0/23", +"119.29.92.0/23", +"119.29.94.0/23", +"119.29.96.0/23", +"119.29.98.0/23", +"119.29.100.0/23", +"119.29.102.0/23", +"119.29.104.0/23", +"119.29.106.0/23", +"119.29.108.0/23", +"119.29.110.0/23", +"119.29.112.0/23", +"119.29.114.0/23", +"119.29.116.0/23", +"119.29.118.0/23", +"119.29.120.0/23", +"119.29.122.0/23", +"119.29.124.0/23", +"119.29.126.0/23", +"119.29.128.0/23", +"119.29.130.0/23", +"119.29.132.0/23", +"119.29.134.0/23", +"119.29.136.0/23", +"119.29.138.0/23", +"119.29.140.0/23", +"119.29.142.0/23", +"119.29.144.0/23", +"119.29.146.0/23", +"119.29.148.0/23", +"119.29.150.0/23", +"119.29.152.0/23", +"119.29.154.0/23", +"119.29.156.0/23", +"119.29.158.0/23", +"119.29.160.0/23", +"119.29.162.0/23", +"119.29.164.0/23", +"119.29.166.0/23", +"119.29.168.0/23", +"119.29.170.0/23", +"119.29.172.0/23", +"119.29.174.0/23", +"119.29.176.0/23", +"119.29.178.0/23", +"119.29.180.0/23", +"119.29.182.0/23", +"119.29.184.0/23", +"119.29.186.0/23", +"119.29.188.0/23", +"119.29.190.0/23", +"119.29.192.0/23", +"119.29.194.0/23", +"119.29.196.0/23", +"119.29.198.0/23", +"119.29.200.0/23", +"119.29.202.0/23", +"119.29.204.0/23", +"119.29.206.0/23", +"119.29.208.0/23", +"119.29.210.0/23", +"119.29.212.0/23", +"119.29.214.0/23", +"119.29.216.0/23", +"119.29.218.0/23", +"119.29.220.0/23", +"119.29.222.0/23", +"119.29.224.0/23", +"119.29.226.0/23", +"119.29.228.0/23", +"119.29.230.0/23", +"119.29.232.0/23", +"119.29.234.0/23", +"119.29.236.0/23", +"119.29.238.0/23", +"119.29.240.0/23", +"119.29.242.0/23", +"119.29.244.0/23", +"119.29.246.0/23", +"119.29.248.0/23", +"119.29.250.0/23", +"119.29.252.0/23", +"119.29.254.0/23", +"121.51.0.0/23", +"121.51.0.0/16", +"121.51.2.0/23", +"121.51.4.0/23", +"121.51.6.0/23", +"121.51.8.0/24", +"121.51.9.0/24", +"121.51.10.0/23", +"121.51.12.0/23", +"121.51.22.0/23", +"121.51.24.0/23", +"121.51.26.0/23", +"121.51.28.0/23", +"121.51.32.0/23", +"121.51.34.0/23", +"121.51.36.0/23", +"121.51.38.0/24", +"121.51.40.0/22", +"121.51.44.0/22", +"121.51.50.0/23", +"121.51.51.0/24", +"121.51.52.0/23", +"121.51.54.0/23", +"121.51.56.0/23", +"121.51.128.0/23", +"121.51.130.0/23", +"121.51.132.0/24", +"121.51.133.0/24", +"121.51.134.0/24", +"121.51.135.0/24", +"121.51.136.0/23", +"121.51.138.0/23", +"121.51.140.0/23", +"121.51.142.0/23", +"121.51.144.0/23", +"121.51.146.0/23", +"121.51.148.0/24", +"121.51.150.0/23", +"121.51.152.0/23", +"121.51.154.0/23", +"121.51.192.0/24", +"121.51.194.0/24", +"121.51.196.0/23", +"121.51.198.0/23", +"121.51.208.0/24", +"121.51.209.0/24", +"121.51.210.0/24", +"121.51.212.0/24", +"121.51.214.0/23", +"121.51.218.0/23", +"121.51.220.0/23", +"121.51.224.0/23", +"122.152.192.0/22", +"122.152.192.0/18", +"122.152.196.0/22", +"122.152.200.0/22", +"122.152.204.0/22", +"122.152.208.0/22", +"122.152.212.0/22", +"122.152.216.0/22", +"122.152.220.0/23", +"122.152.222.0/23", +"122.152.224.0/23", +"122.152.226.0/23", +"122.152.228.0/23", +"122.152.230.0/23", +"122.152.232.0/23", +"122.152.234.0/23", +"122.152.236.0/23", +"122.152.238.0/23", +"122.152.240.0/23", +"122.152.242.0/23", +"123.206.0.0/23", +"123.206.0.0/15", +"123.206.2.0/23", +"123.206.4.0/23", +"123.206.6.0/23", +"123.206.8.0/23", +"123.206.10.0/23", +"123.206.12.0/23", +"123.206.14.0/23", +"123.206.16.0/23", +"123.206.18.0/23", +"123.206.20.0/23", +"123.206.22.0/23", +"123.206.24.0/23", +"123.206.26.0/23", +"123.206.28.0/23", +"123.206.30.0/23", +"123.206.32.0/23", +"123.206.34.0/23", +"123.206.36.0/23", +"123.206.38.0/23", +"123.206.40.0/23", +"123.206.42.0/23", +"123.206.44.0/23", +"123.206.46.0/23", +"123.206.48.0/23", +"123.206.50.0/23", +"123.206.52.0/23", +"123.206.54.0/23", +"123.206.56.0/23", +"123.206.58.0/23", +"123.206.60.0/23", +"123.206.62.0/23", +"123.206.64.0/23", +"123.206.66.0/23", +"123.206.68.0/23", +"123.206.70.0/23", +"123.206.72.0/23", +"123.206.74.0/23", +"123.206.76.0/23", +"123.206.78.0/23", +"123.206.80.0/23", +"123.206.82.0/23", +"123.206.84.0/23", +"123.206.86.0/23", +"123.206.88.0/23", +"123.206.90.0/23", +"123.206.92.0/23", +"123.206.94.0/23", +"123.206.96.0/23", +"123.206.97.0/24", +"123.206.98.0/23", +"123.206.100.0/23", +"123.206.102.0/23", +"123.206.104.0/23", +"123.206.106.0/23", +"123.206.108.0/23", +"123.206.110.0/23", +"123.206.112.0/23", +"123.206.114.0/23", +"123.206.116.0/23", +"123.206.118.0/23", +"123.206.120.0/23", +"123.206.122.0/23", +"123.206.124.0/23", +"123.206.126.0/23", +"123.206.128.0/23", +"123.206.130.0/23", +"123.206.132.0/23", +"123.206.134.0/23", +"123.206.136.0/23", +"123.206.138.0/23", +"123.206.140.0/23", +"123.206.142.0/23", +"123.206.144.0/23", +"123.206.146.0/23", +"123.206.148.0/23", +"123.206.150.0/23", +"123.206.152.0/23", +"123.206.154.0/23", +"123.206.156.0/23", +"123.206.158.0/23", +"123.206.160.0/23", +"123.206.162.0/23", +"123.206.164.0/23", +"123.206.166.0/23", +"123.206.168.0/23", +"123.206.170.0/23", +"123.206.172.0/23", +"123.206.174.0/23", +"123.206.176.0/23", +"123.206.178.0/23", +"123.206.180.0/23", +"123.206.182.0/23", +"123.206.184.0/23", +"123.206.186.0/23", +"123.206.188.0/23", +"123.206.190.0/23", +"123.206.192.0/23", +"123.206.194.0/23", +"123.206.196.0/23", +"123.206.198.0/23", +"123.206.200.0/23", +"123.206.202.0/23", +"123.206.204.0/23", +"123.206.206.0/23", +"123.206.208.0/23", +"123.206.210.0/23", +"123.206.212.0/23", +"123.206.214.0/23", +"123.206.216.0/23", +"123.206.218.0/23", +"123.206.220.0/23", +"123.206.222.0/23", +"123.206.224.0/23", +"123.206.226.0/23", +"123.206.228.0/23", +"123.206.230.0/23", +"123.206.232.0/23", +"123.206.234.0/24", +"123.206.234.0/23", +"123.206.236.0/23", +"123.206.238.0/23", +"123.206.240.0/23", +"123.206.242.0/23", +"123.206.246.0/24", +"123.206.248.0/23", +"123.206.250.0/23", +"123.206.252.0/23", +"123.206.254.0/23", +"123.207.0.0/23", +"123.207.2.0/23", +"123.207.4.0/23", +"123.207.6.0/23", +"123.207.8.0/23", +"123.207.10.0/23", +"123.207.12.0/23", +"123.207.14.0/23", +"123.207.16.0/23", +"123.207.18.0/23", +"123.207.20.0/23", +"123.207.22.0/23", +"123.207.24.0/23", +"123.207.26.0/23", +"123.207.28.0/23", +"123.207.30.0/23", +"123.207.32.0/23", +"123.207.34.0/23", +"123.207.36.0/23", +"123.207.38.0/23", +"123.207.40.0/23", +"123.207.42.0/23", +"123.207.44.0/23", +"123.207.46.0/23", +"123.207.48.0/23", +"123.207.50.0/23", +"123.207.52.0/23", +"123.207.54.0/23", +"123.207.56.0/23", +"123.207.58.0/23", +"123.207.60.0/23", +"123.207.62.0/23", +"123.207.64.0/23", +"123.207.66.0/23", +"123.207.68.0/23", +"123.207.70.0/23", +"123.207.72.0/23", +"123.207.74.0/23", +"123.207.76.0/23", +"123.207.78.0/23", +"123.207.80.0/23", +"123.207.82.0/23", +"123.207.84.0/23", +"123.207.86.0/23", +"123.207.88.0/23", +"123.207.90.0/23", +"123.207.92.0/23", +"123.207.94.0/23", +"123.207.96.0/23", +"123.207.98.0/23", +"123.207.100.0/23", +"123.207.102.0/23", +"123.207.104.0/23", +"123.207.106.0/23", +"123.207.108.0/23", +"123.207.110.0/23", +"123.207.112.0/23", +"123.207.114.0/23", +"123.207.116.0/23", +"123.207.118.0/23", +"123.207.120.0/23", +"123.207.122.0/23", +"123.207.124.0/23", +"123.207.126.0/23", +"123.207.128.0/23", +"123.207.130.0/23", +"123.207.132.0/23", +"123.207.134.0/23", +"123.207.136.0/23", +"123.207.138.0/23", +"123.207.140.0/23", +"123.207.142.0/23", +"123.207.144.0/23", +"123.207.146.0/23", +"123.207.148.0/23", +"123.207.150.0/23", +"123.207.152.0/23", +"123.207.154.0/23", +"123.207.156.0/23", +"123.207.158.0/23", +"123.207.160.0/23", +"123.207.162.0/23", +"123.207.164.0/23", +"123.207.166.0/23", +"123.207.168.0/23", +"123.207.170.0/23", +"123.207.172.0/23", +"123.207.174.0/23", +"123.207.176.0/23", +"123.207.178.0/23", +"123.207.180.0/23", +"123.207.182.0/23", +"123.207.184.0/23", +"123.207.186.0/23", +"123.207.188.0/23", +"123.207.190.0/23", +"123.207.192.0/23", +"123.207.194.0/23", +"123.207.196.0/23", +"123.207.198.0/23", +"123.207.200.0/23", +"123.207.202.0/23", +"123.207.204.0/23", +"123.207.206.0/23", +"123.207.208.0/23", +"123.207.210.0/23", +"123.207.212.0/23", +"123.207.214.0/23", +"123.207.216.0/23", +"123.207.218.0/23", +"123.207.220.0/23", +"123.207.222.0/23", +"123.207.224.0/23", +"123.207.226.0/23", +"123.207.228.0/23", +"123.207.230.0/23", +"123.207.232.0/23", +"123.207.234.0/23", +"123.207.236.0/23", +"123.207.238.0/23", +"123.207.240.0/23", +"123.207.242.0/23", +"123.207.244.0/23", +"123.207.246.0/23", +"123.207.248.0/23", +"123.207.250.0/23", +"123.207.252.0/23", +"123.207.254.0/23", +"139.199.0.0/24", +"139.199.0.0/23", +"139.199.0.0/16", +"139.199.2.0/23", +"139.199.4.0/23", +"139.199.6.0/23", +"139.199.8.0/23", +"139.199.10.0/23", +"139.199.12.0/23", +"139.199.14.0/23", +"139.199.16.0/23", +"139.199.18.0/23", +"139.199.20.0/23", +"139.199.22.0/23", +"139.199.24.0/23", +"139.199.26.0/23", +"139.199.28.0/23", +"139.199.30.0/23", +"139.199.32.0/23", +"139.199.34.0/23", +"139.199.36.0/23", +"139.199.38.0/23", +"139.199.40.0/23", +"139.199.42.0/23", +"139.199.44.0/23", +"139.199.46.0/23", +"139.199.48.0/23", +"139.199.50.0/23", +"139.199.52.0/24", +"139.199.54.0/23", +"139.199.56.0/23", +"139.199.58.0/23", +"139.199.60.0/23", +"139.199.62.0/23", +"139.199.64.0/23", +"139.199.66.0/23", +"139.199.68.0/23", +"139.199.70.0/23", +"139.199.72.0/23", +"139.199.74.0/23", +"139.199.76.0/23", +"139.199.78.0/23", +"139.199.80.0/23", +"139.199.82.0/23", +"139.199.84.0/23", +"139.199.86.0/23", +"139.199.88.0/23", +"139.199.90.0/23", +"139.199.92.0/23", +"139.199.94.0/23", +"139.199.96.0/23", +"139.199.98.0/23", +"139.199.100.0/23", +"139.199.102.0/23", +"139.199.104.0/23", +"139.199.106.0/23", +"139.199.108.0/23", +"139.199.110.0/23", +"139.199.112.0/23", +"139.199.114.0/23", +"139.199.116.0/23", +"139.199.118.0/23", +"139.199.120.0/23", +"139.199.122.0/23", +"139.199.124.0/23", +"139.199.126.0/23", +"139.199.128.0/23", +"139.199.130.0/23", +"139.199.132.0/23", +"139.199.134.0/23", +"139.199.136.0/23", +"139.199.138.0/23", +"139.199.140.0/23", +"139.199.142.0/23", +"139.199.144.0/23", +"139.199.148.0/23", +"139.199.150.0/23", +"139.199.152.0/23", +"139.199.154.0/23", +"139.199.156.0/23", +"139.199.158.0/23", +"139.199.160.0/23", +"139.199.162.0/23", +"139.199.164.0/23", +"139.199.166.0/23", +"139.199.168.0/23", +"139.199.170.0/23", +"139.199.172.0/23", +"139.199.174.0/23", +"139.199.176.0/23", +"139.199.178.0/23", +"139.199.180.0/23", +"139.199.182.0/23", +"139.199.184.0/23", +"139.199.186.0/23", +"139.199.188.0/23", +"139.199.190.0/23", +"139.199.192.0/23", +"139.199.194.0/23", +"139.199.196.0/23", +"139.199.198.0/23", +"139.199.200.0/23", +"139.199.202.0/23", +"139.199.204.0/23", +"139.199.206.0/23", +"139.199.208.0/23", +"139.199.210.0/23", +"139.199.212.0/23", +"139.199.214.0/23", +"139.199.216.0/23", +"139.199.218.0/23", +"139.199.220.0/23", +"139.199.222.0/23", +"139.199.224.0/23", +"139.199.226.0/23", +"139.199.228.0/23", +"139.199.230.0/23", +"139.199.232.0/23", +"139.199.234.0/24", +"139.199.236.0/24", +"139.199.237.0/24", +"139.199.238.0/24", +"139.199.240.0/23", +"139.199.242.0/23", +"139.199.244.0/23", +"139.199.246.0/23", +"139.199.248.0/23", +"139.199.250.0/23", +"139.199.252.0/23", +"139.199.254.0/23", +"140.143.0.0/24", +"140.143.0.0/23", +"140.143.0.0/16", +"140.143.2.0/23", +"140.143.4.0/23", +"140.143.6.0/23", +"140.143.8.0/23", +"140.143.10.0/23", +"140.143.12.0/23", +"140.143.14.0/23", +"140.143.16.0/23", +"140.143.18.0/23", +"140.143.20.0/23", +"140.143.22.0/23", +"140.143.24.0/23", +"140.143.26.0/23", +"140.143.28.0/23", +"140.143.30.0/23", +"140.143.32.0/23", +"140.143.34.0/23", +"140.143.36.0/23", +"140.143.38.0/23", +"140.143.40.0/23", +"140.143.42.0/23", +"140.143.44.0/23", +"140.143.46.0/23", +"182.254.0.0/24", +"182.254.0.0/23", +"182.254.0.0/17", +"182.254.0.0/16", +"182.254.4.0/24", +"182.254.5.0/24", +"182.254.6.0/24", +"182.254.8.0/24", +"182.254.9.0/24", +"182.254.10.0/24", +"182.254.11.0/24", +"182.254.12.0/24", +"182.254.13.0/24", +"182.254.16.0/24", +"182.254.17.0/24", +"182.254.18.0/24", +"182.254.19.0/24", +"182.254.20.0/23", +"182.254.22.0/24", +"182.254.24.0/23", +"182.254.32.0/24", +"182.254.33.0/24", +"182.254.34.0/24", +"182.254.35.0/24", +"182.254.36.0/24", +"182.254.37.0/24", +"182.254.38.0/24", +"182.254.40.0/24", +"182.254.41.0/24", +"182.254.42.0/24", +"182.254.43.0/24", +"182.254.44.0/24", +"182.254.47.0/24", +"182.254.48.0/23", +"182.254.72.0/24", +"182.254.72.0/23", +"182.254.74.0/23", +"182.254.76.0/23", +"182.254.78.0/23", +"182.254.80.0/24", +"182.254.82.0/23", +"182.254.84.0/23", +"182.254.86.0/23", +"182.254.88.0/23", +"182.254.90.0/23", +"182.254.92.0/24", +"182.254.93.0/24", +"182.254.94.0/24", +"182.254.95.0/24", +"182.254.96.0/24", +"182.254.99.0/24", +"182.254.100.0/24", +"182.254.101.0/24", +"182.254.104.0/24", +"182.254.105.0/24", +"182.254.106.0/24", +"182.254.110.0/24", +"182.254.111.0/24", +"182.254.112.0/24", +"182.254.113.0/24", +"182.254.116.0/24", +"182.254.118.0/24", +"182.254.128.0/23", +"182.254.130.0/23", +"182.254.132.0/23", +"182.254.134.0/23", +"182.254.136.0/23", +"182.254.138.0/23", +"182.254.140.0/23", +"182.254.142.0/23", +"182.254.144.0/23", +"182.254.146.0/23", +"182.254.148.0/23", +"182.254.150.0/23", +"182.254.152.0/23", +"182.254.154.0/23", +"182.254.156.0/23", +"182.254.158.0/23", +"182.254.160.0/23", +"182.254.162.0/23", +"182.254.164.0/23", +"182.254.166.0/23", +"182.254.168.0/23", +"182.254.170.0/23", +"182.254.172.0/23", +"182.254.174.0/23", +"182.254.176.0/23", +"182.254.178.0/23", +"182.254.180.0/23", +"182.254.182.0/23", +"182.254.184.0/23", +"182.254.186.0/23", +"182.254.188.0/23", +"182.254.190.0/23", +"182.254.192.0/23", +"182.254.194.0/23", +"182.254.196.0/23", +"182.254.198.0/23", +"182.254.200.0/23", +"182.254.202.0/23", +"182.254.204.0/23", +"182.254.206.0/23", +"182.254.208.0/23", +"182.254.210.0/23", +"182.254.212.0/23", +"182.254.214.0/23", +"182.254.216.0/23", +"182.254.218.0/23", +"182.254.220.0/23", +"182.254.222.0/23", +"182.254.224.0/23", +"182.254.226.0/23", +"182.254.228.0/23", +"182.254.230.0/23", +"182.254.232.0/23", +"182.254.234.0/23", +"182.254.236.0/23", +"182.254.238.0/23", +"182.254.240.0/23", +"182.254.242.0/23", +"182.254.244.0/23", +"182.254.246.0/23", +"182.254.248.0/24", +"203.195.128.0/23", +"203.195.128.0/18", +"203.195.128.0/17", +"203.195.130.0/23", +"203.195.132.0/23", +"203.195.134.0/23", +"203.195.136.0/23", +"203.195.138.0/23", +"203.195.140.0/23", +"203.195.142.0/23", +"203.195.144.0/23", +"203.195.146.0/23", +"203.195.148.0/23", +"203.195.150.0/23", +"203.195.152.0/23", +"203.195.154.0/23", +"203.195.156.0/23", +"203.195.158.0/23", +"203.195.160.0/23", +"203.195.162.0/23", +"203.195.164.0/23", +"203.195.166.0/23", +"203.195.168.0/23", +"203.195.170.0/23", +"203.195.172.0/23", +"203.195.174.0/23", +"203.195.176.0/23", +"203.195.178.0/23", +"203.195.180.0/23", +"203.195.182.0/23", +"203.195.184.0/23", +"203.195.186.0/23", +"203.195.188.0/23", +"203.195.190.0/23", +"203.195.192.0/23", +"203.195.194.0/23", +"203.195.196.0/23", +"203.195.198.0/23", +"203.195.200.0/23", +"203.195.202.0/23", +"203.195.204.0/23", +"203.195.206.0/23", +"203.195.208.0/23", +"203.195.210.0/23", +"203.195.212.0/23", +"203.195.214.0/23", +"203.195.216.0/23", +"203.195.218.0/23", +"203.195.220.0/23", +"203.195.222.0/23", +"203.195.224.0/23", +"203.195.226.0/24", +"203.195.227.0/24", +"203.195.228.0/23", +"203.195.230.0/23", +"203.195.232.0/23", +"203.195.234.0/23", +"203.195.236.0/23", +"203.195.238.0/23", +"203.195.240.0/23", +"203.195.242.0/23", +"203.195.244.0/23", +"203.195.246.0/23", +"203.195.248.0/23", +"203.195.250.0/23", +"203.195.252.0/23", +"203.195.254.0/23", +"210.73.160.0/19", +"211.159.128.0/23", +"211.159.128.0/18", +"211.159.128.0/17", +"211.159.130.0/23", +"211.159.132.0/23", +"211.159.134.0/23", +"211.159.136.0/24", +"211.159.137.0/24", +"211.159.138.0/23", +"211.159.140.0/23", +"211.159.142.0/23", +"211.159.144.0/23", +"211.159.146.0/23", +"211.159.148.0/23", +"211.159.150.0/23", +"211.159.152.0/23", +"211.159.154.0/23", +"211.159.156.0/23", +"211.159.158.0/23", +"211.159.160.0/23", +"211.159.162.0/23", +"211.159.164.0/23", +"211.159.166.0/23", +"211.159.168.0/23", +"211.159.170.0/23", +"211.159.172.0/23", +"211.159.174.0/23", +"211.159.176.0/23", +"211.159.178.0/23", +"211.159.180.0/23", +"211.159.182.0/23", +"211.159.184.0/23", +"211.159.186.0/23", +"211.159.188.0/23", +"211.159.190.0/23", +"211.159.200.0/23", +"211.159.202.0/23", +"211.159.210.0/23", +"211.159.212.0/22", +"211.159.216.0/22", +"211.159.220.0/22", +"211.159.224.0/22", +"211.159.228.0/23", +"211.159.230.0/23", +"211.159.232.0/23", +"211.159.234.0/23", +"211.159.236.0/23", +"211.159.238.0/23", +"211.159.240.0/22", +] +cidr={}.fromkeys([''.join([format(int(w,10),'08b') for w in x.split('.')])[:int(y,10)]\ + for x,y in [x.split('/') for x in cidr]]) + +tmp=[] +for x in cidr: + s='' + v=1 + for i in x: + s=s+i + if s in cidr and s!=x: + v=0 + break + if v: + tmp.append(x) + +tmp=[(format(x,'<032'),len(x)) for x in tmp] +tmp=[(x[0:8],x[8:16],x[16:24],x[24:32],format(y,'b')) for x,y in tmp] +tmp=[list(map(str,map(int,x,[2]*len(x)))) for x in tmp] +tmp=['.'.join(x[0:4])+'/'+x[4] for x in tmp] +print(tmp) diff --git a/README.md b/README.md index add8f3d..720cc81 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # dnspod-httpdns-proxy 使用 dnspod httpdns 来防止劫持的一个小轮子,仅支持 A IN 标准查询 支持提交本地IP来应对穿透造成的解析问题 -## 使用 +提供应答过滤功能,httpdns应答的 __第一个__ IP不在所填的IP段内的话就无应答   +## 使用   __请配合其他强壮的DNS软件共同使用__ ## 需求 -Python3+ +Python3.5+ ## 配置 修改文件```udpdnsserver(addr='0.0.0.0')```来更改本地端口,可选项```addr='127.0.0.1', port=53``` 修改```httpdns(ednsip='211.138.113.115')```来更改提交的IP和应答默认TTL,可选项```ednsip='211.138.113.115', ttl=300``` diff --git a/httpdns.py b/httpdns.py index 46d1360..44aced2 100644 --- a/httpdns.py +++ b/httpdns.py @@ -1,4 +1,4 @@ -#!/usr/bin/env pypy +#!/usr/bin/env python3 # encoding: utf-8 #dnspod httpdns proxy @@ -31,16 +31,165 @@ def labelsTOdomain(self, domain): def httprequest(self, Qdata): self.domain=self.labelsTOdomain(Qdata[:-4]) try: - Rdata=urllib.request.urlopen('http://119.29.29.29/d?dn=%s&ip=%s' % (self.domain,self.ednsip)).read().split(b';') + Rdata_tmp=urllib.request.urlopen('http://119.29.29.29/d?dn=%s&ip=%s' % (self.domain,self.ednsip)).read().split(b';') + # 119.29.29.29, 119.28.28.28, 182.254.116.116, 182.254.118.118 except OSError: print('httprequest error') return 0, Qdata, b'' try: - Rdata=[bytes([int(y) for y in x.split(b'.')]) for x in Rdata] + Rdata=[bytes([int(y) for y in x.split(b'.')]) for x in Rdata_tmp] except ValueError: print('non answer') return 0, Qdata, b'' - return len(Rdata), b''.join([b'\xc0\x0c\x00\x01\x00\x01',self.TTL, b'\x00\x04']).join([Qdata, *Rdata]), Rdata + return len(Rdata), b''.join([b'\xc0\x0c\x00\x01\x00\x01',self.TTL, b'\x00\x04']).join([Qdata, *Rdata]), Rdata_tmp + +class iptool(object): #prefixmatch + + def __init__(self): + self.prefix=[ #china mobile, alicloud, tencentcloud + '36.128.0.0/10', + '39.128.0.0/10', + '43.239.172.0/22', + '43.251.244.0/22', + '45.121.68.0/22', + '45.121.72.0/22', + '45.121.172.0/22', + '45.121.176.0/22', + '45.122.96.0/21', + '45.123.152.0/22', + '45.124.36.0/22', + '45.125.24.0/22', + '103.20.112.0/22', + '103.21.176.0/22', + '103.35.104.0/22', + '103.61.156.0/22', + '103.61.160.0/22', + '103.62.24.0/22', + '103.62.204.0/22', + '103.62.208.0/22', + '103.192.0.0/22', + '103.192.144.0/22', + '103.193.140.0/22', + '111.0.0.0/10', + '112.0.0.0/10', + '117.128.0.0/10', + '120.192.0.0/10', + '183.192.0.0/10', + '211.103.0.0/17', + '211.136.0.0/14', + '211.140.0.0/15', + '211.142.0.0/17', + '211.142.128.0/17', + '211.143.0.0/16', + '218.200.0.0/14', + '218.204.0.0/15', + '218.206.0.0/15', + '221.130.0.0/15', + '221.176.0.0/13', + '223.64.0.0/11', + '223.96.0.0/12', + '223.112.0.0/14', + '223.116.0.0/15', + '223.120.0.0/13', + '39.108.0.0/16', + '42.96.128.0/17', + '42.120.0.0/16', + '42.121.0.0/16', + '42.156.128.0/17', + '45.113.40.0/22', + '47.92.0.0/14', + '59.110.0.0/16', + '60.205.0.0/16', + '101.37.0.0/16', + '101.200.0.0/15', + '103.52.196.0/22', + '106.11.0.0/16', + '106.14.0.0/15', + '110.75.0.0/16', + '110.76.0.0/19', + '110.76.32.0/20', + '110.76.48.0/20', + '110.173.192.0/19', + '112.74.0.0/16', + '112.124.0.0/16', + '112.125.0.0/16', + '112.126.0.0/16', + '112.127.0.0/16', + '114.55.0.0/16', + '114.215.0.0/16', + '115.28.0.0/16', + '115.29.0.0/16', + '115.124.16.0/20', + '116.62.0.0/16', + '118.178.0.0/16', + '118.190.0.0/16', + '119.23.0.0/16', + '119.38.208.0/20', + '119.42.224.0/19', + '120.24.0.0/14', + '120.55.0.0/16', + '120.76.0.0/15', + '120.78.0.0/15', + '121.0.16.0/20', + '121.40.0.0/14', + '121.196.0.0/14', + '123.56.0.0/15', + '139.129.0.0/16', + '139.196.0.0/16', + '139.224.0.0/16', + '140.205.0.0/16', + '182.92.0.0/16', + '203.107.0.0/24', + '203.107.1.0/24', + '203.209.224.0/19', + '218.244.128.0/19', + '223.4.0.0/14', + '43.242.252.0/22', + '43.247.196.0/22', + '58.87.64.0/18', + '103.38.116.0/22', + '103.238.16.0/22', + '111.230.0.0/15', + '115.159.0.0/16', + '118.89.0.0/16', + '118.126.64.0/18', + '119.27.160.0/19', + '119.29.0.0/16', + '121.51.0.0/16', + '122.152.192.0/18', + '123.206.0.0/15', + '139.199.0.0/16', + '140.143.0.0/16', + '182.254.0.0/16', + '203.195.128.0/17', + '210.73.160.0/19', + '211.159.128.0/17', + ] + self.prefix={}.fromkeys([''.join([format(int(w,10),'08b') for w in x.split('.')])[:int(y,10)] for x,y in [x.split('/') for x in self.prefix]]) + self.prefix=self.cidrunique(self.prefix) + + def prefixmatch(self,ip): + ip=''.join([format(int(x,10),'08b') for x in ip.decode("ASCII").split('.')]) + i='' + for x in ip: + i=i+x + if i in self.prefix: + return 1 + return 0 + + def cidrunique (self,cidr): + tmp=[] + for x in cidr: + s='' + v=1 + for i in x: + s=s+i + if s in cidr and s!=x: + v=0 + break + if v: + tmp.append(x) + return {}.fromkeys(tmp) class udpdnsserver(object): @@ -79,18 +228,23 @@ def input(self): def output(self, Rcode, Rdata, ANCOUNT=0): if Rcode: self.flages=self.flages|Rcode - self.flages=self.flages|0x8000 + #self.flages=self.flages|0x8000 #不能直接用请求的flag + self.flages=0x8080 #这样dnsmasq才会缓存结果 Rcount=b''.join([b'\x00\x01', ANCOUNT.to_bytes(2, byteorder='big'), b'\x00\x00\x00\x00']) Rdata=b''.join([self.QID, self.flages.to_bytes(2, byteorder='big'), Rcount, Rdata]) self.udpfd.sendto(Rdata, self.addr) if __name__ == '__main__': localserver=udpdnsserver(addr='0.0.0.0') - dnspod=httpdns(ednsip='211.138.113.115') + dnspod=httpdns(ednsip='211.140.188.188') + ipprefix=iptool() while 1: Rcode, Qdata=localserver.input() if Rcode: - localserver.output(Rcode, Rdata=Qdata) + pass #localserver.output(Rcode, Rdata=Qdata) else: ANCOUNT, Rdata, tmp=dnspod.httprequest(Qdata) - localserver.output(Rcode, Rdata, ANCOUNT) + if ANCOUNT and ipprefix.prefixmatch(tmp[0]): + localserver.output(Rcode, Rdata, ANCOUNT) + else: + pass #localserver.output(Rcode, Rdata=Qdata)