https://zh.wikipedia.org/wiki/各國IPv4位址分配列表
這裡可下載完整的各國 IP 分配表: (3MB+)
http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest
若要查詢某國家 IP 的範圍:
下載全部資料: $ wget http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest -O ip.txt 查詢台灣的 IP 分配範圍: $ cat ip.txt | grep "TW" | grep "ipv4" apnic|TW|ipv4|1.34.0.0|131072|20100505|allocated apnic|TW|ipv4|1.160.0.0|1048576|20100505|allocated apnic|TW|ipv4|1.200.0.0|65536|20110407|allocated :: :: :: 查詢中國的 IP 分配範圍: $ cat ip.txt | grep "CN" | grep "ipv4" apnic|CN|ipv4|1.0.1.0|256|20110414|allocated apnic|CN|ipv4|1.0.2.0|512|20110414|allocated apnic|CN|ipv4|1.0.8.0|2048|20110412|allocated :: :: ::
列出 IP 與網路遮罩:
$ cat ip.txt | awk -F '|' '/TW/&&/ipv4/ {print $4 "/" 32-log($5)/log(2)}' 1.34.0.0/15 1.160.0.0/12 1.200.0.0/16 27.0.152.0/22 27.51.0.0/16 27.52.0.0/15 27.96.224.0/19 27.100.64.0/18 27.105.0.0/16 :: ::懶得下指令的話,這裡可以直接下載各國的 IP 資料
IPdeny IP country CIDR blocks
linux 中要阻擋某些 IP 的連線:
$ iptables -A INPUT -s 123.123.123.123/32 -j DROP 擋單一 IP $ iptables -A INPUT -s 123.123.123.0/24 -j DROP 擋單一整組 class C
2021/11/30 台灣的 IP 範圍
1.34.0.0/15 1.160.0.0/12 1.200.0.0/16 27.0.152.0/22 27.51.0.0/16 27.52.0.0/15 27.96.224.0/19 27.100.64.0/18 27.105.0.0/16 27.147.0.0/18 27.240.0.0/13 36.224.0.0/12 39.1.0.0/16 39.8.0.0/13 42.0.64.0/18 42.64.0.0/12 43.224.20.0/22 43.224.248.0/23 43.226.232.0/22 43.227.24.0/22 43.240.24.0/22 43.240.44.0/22 43.240.104.0/22 43.240.108.0/22 43.240.152.0/22 43.241.32.0/22 43.241.160.0/22 43.243.252.0/22 43.246.188.0/22 43.246.216.0/22 43.248.16.0/22 43.250.44.0/22 43.251.56.0/22 43.251.60.0/22 43.254.16.0/22 43.254.60.0/22 43.255.12.0/22 43.255.88.0/22 43.255.92.0/22 43.255.180.0/22 45.64.28.0/22 45.64.32.0/22 45.64.74.0/23 45.64.228.0/22 45.64.232.0/22 45.113.156.0/22 45.121.48.0/22 45.123.116.0/22 49.128.64.0/19 49.128.112.0/20 49.158.0.0/15 49.213.128.0/17 49.214.0.0/15 49.216.0.0/14 58.86.0.0/16 58.99.0.0/18 58.99.64.0/18 58.114.0.0/15 59.102.128.0/17 59.104.0.0/15 59.112.0.0/13 59.120.0.0/14 59.124.0.0/14 60.198.0.0/16 60.199.0.0/16 60.244.0.0/19 60.244.32.0/19 60.244.64.0/18 60.244.128.0/17 60.245.0.0/18 60.245.64.0/19 60.245.96.0/19 60.248.0.0/16 60.249.0.0/16 60.250.0.0/15 61.20.0.0/16 61.30.0.0/16 61.31.0.0/16 61.56.0.0/13 61.64.0.0/14 61.70.0.0/17 61.70.128.0/17 61.71.0.0/17 61.71.128.0/17 61.216.0.0/16 61.217.0.0/16 61.218.0.0/15 61.220.0.0/14 61.224.0.0/14 61.228.0.0/14 61.247.160.0/20 85.113.86.0/23 85.217.216.0/22 101.0.128.0/17 101.3.0.0/16 101.8.0.0/13 101.101.101.0/24 101.102.103.0/24 101.136.0.0/14 103.1.220.0/22 103.2.216.0/22 103.3.192.0/22 103.4.104.0/22 103.5.32.0/22 103.5.44.0/22 103.5.100.0/22 103.8.104.0/22 103.9.116.0/22 103.10.4.0/22 103.10.204.0/22 103.14.200.0/22 103.16.240.0/22 103.16.244.0/22 103.17.8.0/22 103.17.240.0/22 103.18.128.0/22 103.20.40.0/22 103.20.176.0/22 103.21.60.0/22 103.21.196.0/22 103.22.156.0/22 103.22.212.0/22 103.23.108.0/22 103.24.100.0/22 103.25.232.0/22 103.25.236.0/22 103.28.200.0/23 103.30.44.0/22 103.30.128.0/22 103.30.132.0/22 103.31.196.0/22 103.35.204.0/22 103.36.116.0/22 103.37.36.0/22 103.38.146.0/23 103.42.112.0/23 103.42.144.0/22 103.42.148.0/22 103.43.48.0/22 103.46.144.0/22 103.46.188.0/22 103.51.140.0/22 103.59.220.0/22 103.61.136.0/22 103.67.204.0/22 103.68.138.0/24 103.70.52.0/22 103.71.140.0/22 103.89.20.0/22 103.95.44.0/22 103.97.48.0/22 103.97.156.0/22 103.98.72.0/22 103.99.88.0/22 103.100.124.0/22 103.100.164.0/22 103.103.80.0/22 103.103.128.0/22 103.104.148.0/22 103.106.52.0/22 103.112.48.0/22 103.113.240.0/22 103.116.68.0/22 103.116.96.0/22 103.117.4.0/22 103.117.40.0/22 103.117.106.0/24 103.117.112.0/22 103.117.224.0/22 103.118.24.0/22 103.119.212.0/22 103.120.148.0/22 103.122.16.0/22 103.122.20.0/22 103.122.116.0/22 103.122.124.0/22 103.122.148.0/22 103.122.188.0/22 103.122.196.0/22 103.122.208.0/22 103.122.216.0/22 103.122.224.0/22 103.122.236.0/22 103.123.0.0/22 103.123.124.0/22 103.123.128.0/22 103.123.132.0/22 103.123.140.0/22 103.123.184.0/22 103.123.188.0/22 103.123.192.0/22 103.123.196.0/22 103.123.216.0/22 103.123.240.0/22 103.123.252.0/22 103.124.40.0/22 103.124.72.0/22 103.124.148.0/22 103.124.176.0/22 103.124.252.0/22 103.125.0.0/22 103.125.64.0/22 103.125.156.0/22 103.125.224.0/22 103.125.228.0/22 103.126.88.0/22 103.126.140.0/22 103.126.164.0/22 103.126.180.0/22 103.126.252.0/22 103.127.148.0/22 103.127.228.0/22 103.127.232.0/22 103.127.236.0/22 103.127.240.0/22 103.129.136.0/22 103.129.144.0/22 103.129.160.0/22 103.129.164.0/22 103.129.168.0/22 103.129.176.0/22 103.129.180.0/22 103.129.240.0/22 103.130.0.0/22 103.130.20.0/22 103.130.24.0/22 103.130.28.0/22 103.130.32.0/22 103.130.36.0/22 103.130.40.0/22 103.130.44.0/22 103.130.48.0/22 103.130.84.0/22 103.130.92.0/22 103.130.96.0/22 103.130.100.0/22 103.130.120.0/22 103.130.124.0/22 103.130.248.0/22 103.130.252.0/22 103.131.112.0/22 103.131.124.0/22 103.131.172.0/22 103.131.252.0/22 103.132.44.0/22 103.132.132.0/22 103.132.156.0/22 103.133.44.0/22 103.133.152.0/22 103.134.80.0/22 103.134.120.0/22 103.134.148.0/22 103.135.16.0/22 103.135.20.0/22 103.135.116.0/22 103.136.60.0/23 103.136.210.0/23 103.136.212.0/23 103.136.224.0/23 103.137.22.0/23 103.137.62.0/23 103.137.98.0/23 103.137.246.0/23 103.138.92.0/23 103.138.106.0/23 103.138.194.0/23 103.139.240.0/23 103.140.110.0/23 103.140.169.0/24 103.140.232.0/23 103.141.76.0/24 103.141.80.0/23 103.141.82.0/23 103.142.42.0/23 103.142.44.0/23 103.142.150.0/23 103.142.152.0/23 103.142.176.0/23 103.143.56.0/23 103.144.32.0/23 103.144.34.0/23 103.145.22.0/23 103.146.80.0/23 103.146.164.0/23 103.146.210.0/23 103.146.212.0/23 103.146.250.0/23 103.147.22.0/23 103.147.58.0/23 103.147.130.0/23 103.148.68.0/23 103.148.72.0/23 103.148.142.0/23 103.148.146.0/23 103.149.64.0/23 103.149.66.0/23 103.150.36.0/23 103.150.230.0/23 103.152.150.0/23 103.152.202.0/23 103.152.220.0/23 103.152.252.0/23 103.153.176.0/23 103.153.200.0/23 103.155.202.0/23 103.156.116.0/23 103.156.184.0/23 103.156.242.0/23 103.157.42.0/23 103.157.86.0/23 103.158.74.0/23 103.158.76.0/23 103.158.78.0/23 103.158.80.0/23 103.158.112.0/23 103.158.114.0/23 103.158.116.0/23 103.158.118.0/23 103.158.134.0/23 103.158.184.0/23 103.158.186.0/23 103.158.228.0/23 103.159.86.0/23 103.159.88.0/23 103.159.118.0/23 103.159.120.0/23 103.159.172.0/23 103.159.176.0/23 103.159.206.0/23 103.159.210.0/23 103.160.0.0/23 103.160.86.0/23 103.160.180.0/23 103.160.214.0/23 103.160.220.0/23 103.160.224.0/23 103.160.226.0/23 103.160.250.0/23 103.161.6.0/23 103.161.8.0/23 103.161.10.0/23 103.161.12.0/23 103.161.36.0/23 103.161.78.0/23 103.161.90.0/23 103.162.84.0/23 103.164.130.0/23 103.166.81.0/24 103.167.50.0/23 103.167.250.0/23 103.168.154.0/23 103.168.156.0/23 103.169.46.0/23 103.169.106.0/23 103.169.126.0/23 103.169.212.0/23 103.170.14.0/23 103.172.124.0/23 103.172.126.0/23 103.172.128.0/23 103.173.94.0/23 103.174.124.0/24 103.174.154.0/23 103.175.152.0/23 103.175.166.0/23 103.175.194.0/23 103.175.254.0/23 103.176.0.0/23 103.176.50.0/23 103.177.32.0/23 103.177.50.0/23 103.196.172.0/22 103.197.172.0/22 103.200.0.0/22 103.207.252.0/22 103.208.196.0/23 103.222.248.0/22 103.224.132.0/22 103.224.192.0/22 103.224.200.0/22 103.224.204.0/22 103.225.0.0/22 103.226.100.0/22 103.226.212.0/22 103.227.32.0/22 103.227.224.0/22 103.228.216.0/22 103.229.16.0/22 103.229.50.0/24 103.229.100.0/22 103.229.124.0/22 103.229.132.0/22 103.231.48.0/22 103.233.68.0/22 103.234.40.0/22 103.234.76.0/22 103.234.80.0/22 103.234.204.0/22 103.234.224.0/22 103.234.228.0/22 103.235.88.0/22 103.239.60.0/22 103.241.68.0/22 103.243.248.0/22 103.246.208.0/22 103.246.218.0/23 103.247.112.0/22 103.249.160.0/22 103.252.68.0/22 103.252.128.0/22 103.252.196.0/22 103.252.244.0/24 103.253.184.0/22 106.1.0.0/16 106.64.0.0/15 106.104.0.0/14 110.24.0.0/13 110.50.128.0/18 111.67.48.0/20 111.70.0.0/15 111.80.0.0/14 111.125.128.0/21 111.184.0.0/15 111.235.192.0/18 111.240.0.0/12 112.78.16.0/20 112.78.64.0/19 112.78.104.0/21 112.104.0.0/15 112.121.32.0/20 112.121.64.0/18 112.213.48.0/20 113.21.80.0/20 113.21.160.0/19 113.61.128.0/17 113.196.0.0/16 113.212.78.0/23 114.24.0.0/14 114.29.240.0/22 114.29.244.0/22 114.30.32.0/20 114.32.0.0/12 114.136.0.0/15 114.140.0.0/16 114.198.160.0/20 114.198.176.0/20 115.30.64.0/18 115.42.80.0/20 115.42.112.0/21 115.43.0.0/16 115.80.0.0/14 115.85.144.0/20 115.165.192.0/18 116.50.32.0/20 116.59.0.0/16 116.89.128.0/20 116.118.128.0/18 116.212.80.0/20 116.214.0.0/20 116.241.0.0/16 117.19.0.0/16 117.56.0.0/16 117.103.96.0/20 118.99.128.0/17 118.150.0.0/16 118.160.0.0/13 118.168.0.0/14 118.231.0.0/16 118.232.0.0/15 119.14.0.0/16 119.15.192.0/18 119.30.16.0/20 119.31.176.0/20 119.75.240.0/20 119.77.128.0/17 119.160.240.0/20 120.96.0.0/11 121.50.144.0/21 121.50.176.0/20 121.254.64.0/18 122.99.0.0/18 122.100.64.0/18 122.116.0.0/15 122.118.0.0/16 122.120.0.0/13 122.128.80.0/21 122.144.32.0/19 122.146.0.0/15 122.200.152.0/21 122.201.128.0/17 122.252.160.0/20 122.254.0.0/18 122.255.80.0/20 123.0.32.0/19 123.0.192.0/18 123.50.32.0/19 123.51.128.0/17 123.99.0.0/19 123.99.32.0/19 123.110.0.0/16 123.192.0.0/14 123.204.0.0/15 123.240.0.0/15 123.252.0.0/17 123.253.140.0/23 123.255.224.0/21 124.6.0.0/19 124.8.0.0/14 124.12.0.0/16 124.29.128.0/19 124.29.160.0/19 124.108.128.0/18 124.109.112.0/20 124.150.128.0/21 124.155.128.0/19 124.155.160.0/19 124.199.64.0/19 124.199.96.0/20 124.218.0.0/16 124.219.0.0/17 125.62.224.0/20 125.224.0.0/13 125.232.0.0/15 134.208.0.0/16 139.175.0.0/16 139.223.0.0/16 140.92.0.0/16 140.96.0.0/16 140.109.0.0/16 140.110.0.0/16 140.111.0.0/16 140.112.0.0/16 140.113.0.0/16 140.114.0.0/16 140.115.0.0/16 140.116.0.0/14 140.120.0.0/13 140.128.0.0/16 140.129.0.0/16 140.130.0.0/16 140.131.0.0/16 140.132.0.0/16 140.133.0.0/16 140.134.0.0/16 140.135.0.0/16 140.136.0.0/15 140.138.0.0/16 150.107.56.0/22 150.107.60.0/22 150.107.64.0/22 150.116.0.0/15 150.129.36.0/22 150.129.72.0/22 150.129.96.0/22 150.129.228.0/22 150.242.100.0/22 159.117.64.0/19 160.19.52.0/22 163.13.0.0/16 163.14.0.0/15 163.16.0.0/12 163.32.0.0/16 168.95.0.0/16 175.41.48.0/20 175.96.0.0/14 175.111.32.0/19 175.111.192.0/18 175.180.0.0/14 175.184.240.0/21 180.92.0.0/20 180.176.0.0/15 180.204.0.0/14 180.214.176.0/20 180.217.0.0/16 180.218.0.0/16 182.54.136.0/22 182.155.0.0/16 182.173.0.0/18 182.233.0.0/16 182.234.0.0/15 185.167.12.0/22 192.72.3.0/24 192.72.4.0/24 192.72.5.0/24 192.72.6.0/24 192.72.7.0/24 192.72.8.0/24 192.72.9.0/24 192.72.10.0/24 192.72.11.0/24 192.72.12.0/24 192.72.13.0/24 192.72.14.0/24 192.72.15.0/24 192.72.16.0/24 192.72.17.0/24 192.72.18.0/24 192.72.19.0/24 192.72.20.0/24 192.72.21.0/24 192.72.22.0/24 192.72.23.0/24 192.72.24.0/24 192.72.25.0/24 192.72.26.0/24 192.72.27.0/24 192.72.28.0/24 192.72.29.0/24 192.72.30.0/24 192.72.31.0/24 192.72.32.0/24 192.72.33.0/24 192.72.34.0/23 192.72.36.0/22 192.72.40.0/21 192.72.48.0/20 192.72.64.0/18 192.72.128.0/22 192.72.132.0/24 192.72.133.0/24 192.72.134.0/23 192.72.136.0/21 192.72.144.0/20 192.72.160.0/19 192.72.192.0/19 192.72.224.0/20 192.72.240.0/21 192.72.248.0/22 192.72.252.0/24 192.83.166.0/24 192.83.167.0/24 192.83.168.0/24 192.83.169.0/24 192.83.170.0/24 192.83.171.0/24 192.83.172.0/24 192.83.173.0/24 192.83.174.0/24 192.83.175.0/24 192.83.176.0/24 192.83.177.0/24 192.83.178.0/24 192.83.179.0/24 192.83.180.0/24 192.83.181.0/24 192.83.182.0/23 192.83.184.0/24 192.83.185.0/24 192.83.186.0/24 192.83.187.0/24 192.83.188.0/24 192.83.189.0/24 192.83.190.0/24 192.83.191.0/24 192.83.192.0/24 192.83.193.0/24 192.83.194.0/23 192.83.196.0/24 192.188.171.0/24 192.192.0.0/17 192.192.128.0/19 192.192.160.0/22 192.192.164.0/24 192.192.165.0/24 192.192.166.0/23 192.192.168.0/21 192.192.176.0/20 192.192.192.0/18 193.149.158.0/23 193.149.166.0/23 202.2.52.0/22 202.3.160.0/19 202.5.4.0/23 202.5.8.0/22 202.5.12.0/22 202.5.224.0/19 202.6.104.0/23 202.8.14.0/23 202.12.76.0/22 202.39.0.0/16 202.41.146.0/24 202.55.224.0/19 202.59.250.0/23 202.80.104.0/21 202.123.124.0/22 202.126.64.0/20 202.132.0.0/16 202.133.224.0/19 202.140.160.0/19 202.144.208.0/20 202.145.32.0/19 202.145.64.0/18 202.145.128.0/18 202.145.192.0/19 202.145.224.0/19 202.148.208.0/20 202.151.48.0/20 202.153.4.0/23 202.153.160.0/19 202.153.192.0/20 202.154.192.0/19 202.160.64.0/19 202.165.128.0/20 202.165.144.0/20 202.168.192.0/20 202.169.160.0/20 202.173.32.0/19 202.174.4.0/24 202.174.16.0/20 202.178.128.0/18 202.178.192.0/19 202.178.224.0/19 203.15.150.0/24 203.55.118.0/24 203.64.0.0/14 203.68.0.0/14 203.72.0.0/14 203.77.0.0/22 203.77.4.0/22 203.77.8.0/21 203.77.16.0/20 203.77.32.0/20 203.77.48.0/20 203.77.64.0/19 203.77.96.0/19 203.78.0.0/22 203.78.176.0/20 203.79.128.0/18 203.79.192.0/19 203.79.224.0/19 203.80.169.0/24 203.84.144.0/21 203.91.0.0/19 203.105.224.0/19 203.111.208.0/20 203.118.224.0/20 203.119.3.0/24 203.119.94.0/24 203.121.224.0/20 203.121.240.0/20 203.133.0.0/19 203.133.32.0/19 203.133.64.0/19 203.133.96.0/19 203.135.64.0/19 203.145.192.0/20 203.145.208.0/20 203.148.92.0/24 203.160.144.0/20 203.160.224.0/19 203.163.192.0/19 203.187.0.0/19 203.187.32.0/19 203.187.64.0/18 203.188.192.0/20 203.190.16.0/21 203.201.32.0/20 203.203.0.0/17 203.203.128.0/17 203.204.0.0/17 203.204.128.0/17 203.207.0.0/20 203.207.32.0/20 203.211.0.0/19 203.217.96.0/19 203.222.0.0/20 203.222.16.0/20 210.17.0.0/17 210.58.0.0/17 210.58.128.0/17 210.59.0.0/16 210.60.0.0/14 210.64.0.0/14 210.68.0.0/14 210.80.64.0/20 210.80.80.0/20 210.85.0.0/16 210.192.0.0/18 210.192.128.0/17 210.200.0.0/19 210.200.32.0/19 210.200.64.0/19 210.200.96.0/19 210.200.128.0/19 210.200.160.0/19 210.200.192.0/18 210.201.0.0/18 210.201.64.0/18 210.201.128.0/18 210.201.192.0/20 210.201.208.0/20 210.201.224.0/19 210.202.0.0/16 210.203.0.0/17 210.208.0.0/18 210.208.64.0/19 210.208.96.0/19 210.208.128.0/18 210.208.192.0/18 210.209.0.0/18 210.209.128.0/20 210.209.144.0/20 210.209.160.0/19 210.209.192.0/18 210.211.24.0/21 210.240.0.0/16 210.241.0.0/16 210.242.0.0/15 210.244.0.0/17 210.244.128.0/17 211.20.0.0/14 211.72.0.0/14 211.76.0.0/14 216.107.240.0/20 218.32.0.0/16 218.34.0.0/17 218.34.128.0/17 218.35.0.0/16 218.160.0.0/14 218.164.0.0/15 218.166.0.0/15 218.168.0.0/13 218.184.0.0/16 218.187.0.0/17 218.187.128.0/17 218.210.0.0/15 219.68.0.0/17 219.68.128.0/17 219.69.0.0/16 219.70.0.0/15 219.80.0.0/15 219.84.0.0/15 219.86.0.0/15 219.90.0.0/18 219.91.0.0/17 220.128.0.0/18 220.128.64.0/18 220.128.128.0/17 220.129.0.0/16 220.130.0.0/15 220.132.0.0/14 220.136.0.0/13 220.157.112.0/20 220.158.228.0/22 220.228.0.0/15 221.120.0.0/18 221.120.64.0/19 221.169.0.0/16 222.156.0.0/16 222.157.0.0/16 222.250.0.0/16 222.251.0.0/17 223.22.0.0/15 223.26.0.0/20 223.26.64.0/18 223.27.32.0/19 223.136.0.0/13 223.165.8.0/21 223.200.0.0/16