ficapy
8/22/2016 - 10:14 AM

列出CloudFront的ip所在地

列出CloudFront的ip所在地

====================================================================================================100% 617/617 United States
54.238.0.0 Japan
54.144.0.0 United States
52.95.248.0 Germany
54.215.0.0 United States
54.241.0.0 United States
52.93.12.0 United States
52.95.36.0 Australia
52.220.0.0 Singapore
52.95.249.0 India
54.148.0.0 United States
52.95.255.96 United States
52.93.16.0 United States
52.95.40.0 United States
54.216.0.0 Ireland
52.95.251.0 United States
54.150.0.0 Japan
52.95.255.112 United States
54.218.0.0 United States
52.94.0.0 United States
52.95.48.0 United States
52.95.255.128 Germany
52.95.252.0 Republic of Korea
54.151.0.0 United States
54.219.0.0 United States
52.94.4.0 United States
52.95.52.0 United States
52.95.255.144 China
52.95.255.0 Brazil
54.151.128.0 Singapore
54.220.0.0 Ireland
52.94.5.0 Ireland
52.95.56.0 Japan
52.192.0.0 Japan
52.95.255.16 Australia
54.152.0.0 United States
54.221.0.0 United States
52.94.6.0 Republic of Korea
52.95.60.0 Ireland
52.196.0.0 Japan
52.95.255.32 Singapore
54.153.0.0 United States
54.222.128.0 China
52.94.7.0 Brazil
52.95.61.0 Ireland
52.200.0.0 United States
52.95.255.48 Japan
54.153.128.0 Australia
54.223.0.0 China
52.94.8.0 Japan
52.95.62.0 United States
52.208.0.0 Ireland
52.95.255.64 Ireland
54.154.0.0 Ireland
54.224.0.0 United States
52.94.9.0 United States
52.95.63.0 United States
52.216.0.0 United States
52.95.255.80 United States
54.155.0.0 Ireland
54.226.0.0 United States
52.94.10.0 United States
52.95.64.0 India
52.218.0.0 Ireland
52.95.255.96 United States
54.156.0.0 United States
54.228.0.0 Ireland
52.94.11.0 Singapore
52.95.80.0 India
52.218.64.0 Ireland
52.95.255.112 United States
54.160.0.0 United States
54.229.0.0 Ireland
52.94.12.0 United States
52.95.96.0 India
52.218.128.0 United States
52.95.255.128 Germany
54.168.0.0 Japan
54.232.0.0 Brazil
52.94.13.0 Australia
52.95.100.0 United States
52.218.192.0 United States
52.95.255.144 China
54.169.0.0 Singapore
54.233.0.0 Brazil
52.94.192.0 United States
52.95.104.0 Ireland
52.219.0.0 Japan
52.192.0.0 Japan
54.170.0.0 Ireland
54.233.64.0 Brazil
52.94.196.0 United States
52.95.128.0 Australia
52.219.16.0 Japan
52.196.0.0 Japan
54.172.0.0 United States
52.94.197.0 United States
52.95.132.0 Australia
52.200.0.0 United States
54.174.0.0 United States
52.94.198.0 United States
52.95.192.0 Republic of Korea
52.208.0.0 Ireland
54.176.0.0 United States
52.94.198.16 United States
52.95.212.0 Singapore
52.220.0.0 Singapore
54.178.0.0 Japan
52.94.198.32 United States
52.95.240.0 Brazil
52.222.0.0 United States
54.179.0.0 Singapore
54.236.0.0 United States
52.94.198.48 United States
52.95.241.0 Australia
52.219.32.0 Singapore
54.64.0.0 Japan
54.183.0.0 United States
52.219.24.0 United States
52.94.198.64 United States
52.95.242.0 Singapore
54.66.0.0 Australia
54.184.0.0 United States
54.234.0.0 United States
52.94.198.80 United States
52.95.243.0 Japan
54.67.0.0 United States
54.193.0.0 United States
52.94.204.0 Germany
52.95.244.0 Ireland
54.68.0.0 United States
54.194.0.0 Ireland
52.94.206.0 Brazil
52.95.245.0 United States
54.72.0.0 Ireland
54.196.0.0 United States
52.94.208.0 United States
52.95.246.0 United States
54.74.0.0 Ireland
54.198.0.0 United States
52.94.216.0 Ireland
52.95.247.0 United States
54.76.0.0 Ireland
54.199.0.0 Japan
52.94.224.0 United States
52.95.248.0 Germany
54.78.0.0 Ireland
54.200.0.0 United States
52.94.252.0 United States
52.95.249.0 India
54.79.0.0 Australia
54.202.0.0 United States
52.94.254.0 United States
52.95.251.0 United States
54.80.0.0 United States
54.204.0.0 United States
52.95.0.0 United States
52.95.252.0 Republic of Korea
54.88.0.0 United States
54.206.0.0 Australia
52.95.16.0 United States
52.95.255.0 Brazil
54.92.0.0 Japan
54.207.0.0 Brazil
52.95.24.0 United States
52.95.255.16 Australia
54.92.128.0 United States
54.208.0.0 United States
52.95.28.0 United States
52.95.255.32 Singapore
54.93.0.0 Germany
54.210.0.0 United States
52.95.30.0 Japan
52.95.255.48 Japan
54.94.0.0 Brazil
54.212.0.0 United States
52.95.34.0 Japan
52.95.255.64 Ireland
54.214.0.0 United States
54.95.0.0 Japan
52.95.255.80 United States
52.95.35.0 Singapore
52.222.128.0 United States
185.48.120.0 Ireland
52.32.0.0 United States
54.216.0.0 Ireland
185.143.16.0 Ireland
52.70.0.0 United States
54.182.0.0 United States
203.83.220.0 Singapore
52.36.0.0 United States
54.218.0.0 United States
204.236.128.0 United States
52.72.0.0 United States
52.219.20.0 United States
54.192.0.0 United States
204.236.192.0 United States
52.40.0.0 United States
54.219.0.0 United States
204.246.160.0 United States
52.74.0.0 Singapore
54.230.0.0 United States
204.246.164.0 United States
52.44.0.0 United States
54.220.0.0 Ireland
204.246.168.0 United States
52.76.0.0 Singapore
54.239.128.0 United States
204.246.174.0 United States
52.48.0.0 Ireland
54.221.0.0 United States
204.246.176.0 United States
52.76.128.0 Singapore
54.239.192.0 United States
205.251.192.0 United States
52.52.0.0 United States
54.222.0.0 China
205.251.224.0 United States
52.77.0.0 Singapore
54.240.128.0 United States
205.251.228.0 United States
52.54.0.0 United States
54.222.58.0 China
205.251.232.0 United States
52.78.0.0 Republic of Korea
204.246.164.0 United States
205.251.236.0 United States
52.57.0.0 United States
54.222.128.0 China
205.251.240.0 United States
52.79.0.0 Republic of Korea
204.246.168.0 United States
205.251.244.0 United States
52.58.0.0 Germany
54.223.0.0 China
205.251.247.0 United States
52.80.0.0 China
204.246.174.0 United States
205.251.248.0 United States
52.62.0.0 Australia
54.224.0.0 United States
205.251.249.0 United States
52.84.0.0 United States
204.246.176.0 United States
205.251.250.0 United States
52.64.0.0 Australia
54.226.0.0 United States
205.251.252.0 United States
52.86.0.0 United States
205.251.192.0 United States
205.251.254.0 United States
52.64.128.0 Australia
54.228.0.0 Ireland
205.251.255.0 United States
52.88.0.0 United States
205.251.249.0 United States
207.171.160.0 United States
52.65.0.0 Australia
54.229.0.0 Ireland
207.171.176.0 United States
52.90.0.0 United States
205.251.250.0 United States
216.137.32.0 United States
52.66.0.0 India
54.230.0.0 United States
216.182.224.0 United States
52.92.0.0 Republic of Korea
205.251.252.0 United States
23.20.0.0 United States
52.67.0.0 Brazil
54.231.0.0 United States
46.51.128.0 Ireland
52.92.16.0 United States
205.251.254.0 United States
46.51.192.0 Ireland
52.68.0.0 Japan
54.231.128.0 Ireland
46.51.216.0 Singapore
52.92.32.0 United States
216.137.32.0 United States
46.51.224.0 Japan
52.70.0.0 United States
54.231.160.0 United States
46.137.0.0 Ireland
52.92.39.0 Brazil
46.137.128.0 Ireland
52.72.0.0 United States
54.231.192.0 Germany
46.137.192.0 Singapore
52.92.40.0 Ireland
54.231.224.0 Japan
46.137.224.0 Singapore
52.74.0.0 Singapore
54.231.232.0 United States
50.16.0.0 United States
52.92.48.0 United States
54.231.240.0 Singapore
50.18.0.0 United States
52.76.0.0 Singapore
54.231.244.0 United States
50.19.0.0 United States
52.92.52.0 Australia
54.231.248.0 Australia
50.112.0.0 United States
52.76.128.0 Singapore
54.231.252.0 Australia
52.0.0.0 United States
52.92.56.0 Singapore
54.231.253.0 Brazil
52.40.0.0 United States
52.77.0.0 Singapore
54.231.254.0 United States
52.2.0.0 United States
52.92.60.0 Japan
54.232.0.0 Brazil
52.44.0.0 United States
52.78.0.0 Republic of Korea
54.233.0.0 Brazil
52.4.0.0 United States
52.92.64.0 Brazil
54.233.64.0 Brazil
52.46.0.0 United States
52.79.0.0 Republic of Korea
54.233.128.0 Brazil
52.8.0.0 United States
52.92.68.0 Germany
54.234.0.0 United States
52.48.0.0 Ireland
52.80.0.0 China
54.236.0.0 United States
52.9.0.0 United States
52.92.72.0 Brazil
54.238.0.0 Japan
52.52.0.0 United States
52.86.0.0 United States
54.239.2.0 United States
52.10.0.0 United States
52.92.76.0 United States
54.239.4.0 Germany
52.54.0.0 United States
52.88.0.0 United States
54.239.8.0 United States
52.12.0.0 United States
52.92.80.0 Japan
54.239.16.0 United States
52.57.0.0 United States
52.90.0.0 United States
54.239.32.0 Ireland
52.15.0.0 United States
52.92.92.0 Australia
54.239.48.0 United States
52.58.0.0 Germany
52.95.240.0 Brazil
54.239.52.0 Japan
52.16.0.0 Ireland
52.92.248.0 India
54.239.54.0 Germany
54.233.128.0 Brazil
52.95.241.0 Australia
54.239.56.0 Germany
52.62.0.0 Australia
52.92.252.0 United States
54.239.64.0 United States
52.18.0.0 Ireland
52.95.242.0 Singapore
54.239.96.0 Japan
52.64.0.0 Australia
52.93.0.0 Ireland
54.239.98.0 United States
52.20.0.0 United States
52.95.243.0 Japan
54.239.99.0 Ireland
52.64.128.0 Australia
52.93.1.0 United States
54.239.100.0 Ireland
52.24.0.0 United States
52.95.244.0 Ireland
54.239.104.0 United States
52.65.0.0 Australia
52.93.2.0 Ireland
54.239.108.0 United States
52.28.0.0 Germany
52.95.245.0 United States
54.239.114.0 Ireland
52.66.0.0 India
52.93.3.0 United States
54.239.116.0 Republic of Korea
52.29.0.0 Germany
52.95.246.0 United States
54.242.0.0 United States
54.239.120.0 Republic of Korea
52.67.0.0 Brazil
52.222.0.0 United States
54.239.128.0 United States
52.30.0.0 Ireland
52.93.4.0 United States
54.244.0.0 United States
54.239.192.0 United States
52.68.0.0 Japan
52.95.247.0 United States
52.93.8.0 Singapore
54.240.128.0 United States
54.240.192.0 Australia
54.240.196.0 United States
54.240.197.0 Ireland
54.240.198.0 United States
54.240.199.0 Singapore
54.240.200.0 Japan
54.240.202.0 United States
54.240.203.0 Australia
54.240.204.0 Australia
54.240.208.0 United States
54.240.212.0 United States
54.240.216.0 United States
54.240.220.0 Ireland
54.240.225.0 Japan
54.240.226.0 Singapore
54.240.227.0 Singapore
54.240.228.0 United States
54.240.230.0 United States
54.240.232.0 United States
54.240.236.0 Republic of Korea
54.240.240.0 Germany
54.240.244.0 Brazil
54.240.248.0 United States
54.241.0.0 United States
54.242.0.0 United States
54.244.0.0 United States
54.245.0.0 United States
54.246.0.0 Ireland
54.247.0.0 Ireland
54.248.0.0 Japan
54.250.0.0 Japan
54.251.0.0 Singapore
54.252.0.0 Australia
54.253.0.0 Australia
54.254.0.0 Singapore
54.255.0.0 Singapore
67.202.0.0 United States
72.21.192.0 United States
72.44.32.0 United States
75.101.128.0 United States
79.125.0.0 Ireland
87.238.80.0 Ireland
96.127.0.0 United States
103.4.8.0 Japan
103.8.172.0 Australia
103.246.148.0 Singapore
103.246.150.0 Japan
107.20.0.0 United States
122.248.192.0 Singapore
172.96.97.0 United States
174.129.0.0 United States
175.41.128.0 Singapore
175.41.192.0 Japan
176.32.64.0 Japan
176.32.96.0 United States
176.32.104.0 Ireland
176.32.112.0 United States
176.32.120.0 United States
176.32.125.0 United States
176.34.0.0 Japan
176.34.32.0 Japan
176.34.64.0 Ireland
176.34.128.0 Ireland
177.71.128.0 Brazil
177.72.240.0 Brazil
178.236.0.0 Ireland
184.72.0.0 United States
184.72.64.0 United States
184.72.128.0 United States
184.73.0.0 United States
184.169.128.0 United States
52.222.128.0 United States
54.155.0.0 Ireland
54.245.0.0 United States
177.71.128.0 Brazil
54.64.0.0 Japan
52.9.0.0 United States
54.246.0.0 Ireland
54.156.0.0 United States
54.66.0.0 Australia
184.72.0.0 United States
54.247.0.0 Ireland
52.10.0.0 United States
54.67.0.0 United States
54.160.0.0 United States
54.248.0.0 Japan
184.72.64.0 United States
54.68.0.0 United States
52.12.0.0 United States
54.250.0.0 Japan
54.168.0.0 Japan
54.72.0.0 Ireland
184.72.128.0 United States
54.251.0.0 Singapore
52.15.0.0 United States
23.20.0.0 United States
54.169.0.0 Singapore
54.74.0.0 Ireland
184.73.0.0 United States
54.252.0.0 Australia
52.16.0.0 Ireland
54.76.0.0 Ireland
54.170.0.0 Ireland
54.253.0.0 Australia
184.169.128.0 United States
46.51.128.0 Ireland
52.18.0.0 Ireland
54.78.0.0 Ireland
54.172.0.0 United States
54.254.0.0 Singapore
185.48.120.0 Ireland
43.250.193.0 Singapore
52.20.0.0 United States
54.79.0.0 Australia
54.174.0.0 United States
54.255.0.0 Singapore
204.236.128.0 United States
46.51.192.0 Ireland
52.24.0.0 United States
54.80.0.0 United States
54.176.0.0 United States
67.202.0.0 United States
204.236.192.0 United States
46.51.216.0 Singapore
52.28.0.0 Germany
54.88.0.0 United States
54.178.0.0 Japan
72.44.32.0 United States
216.182.224.0 United States
27.0.0.0 Japan
52.29.0.0 Germany
54.92.0.0 Japan
54.179.0.0 Singapore
75.101.128.0 United States
205.251.192.0 United States
43.250.192.0 Singapore
52.30.0.0 Ireland
54.92.128.0 United States
54.182.0.0 United States
79.125.0.0 Ireland
54.183.255.128 United States
46.51.224.0 Japan
52.32.0.0 United States
54.93.0.0 Germany
54.183.0.0 United States
96.127.0.0 United States
54.228.16.0 Ireland
46.137.0.0 Ireland
52.36.0.0 United States
54.94.0.0 Brazil
54.184.0.0 United States
103.4.8.0 Japan
54.232.40.64 Brazil
46.137.128.0 Ireland
54.192.0.0 United States
54.95.0.0 Japan
54.241.32.64 United States
107.20.0.0 United States
54.193.0.0 United States
46.137.192.0 Singapore
54.243.31.192 United States
54.144.0.0 United States
54.194.0.0 Ireland
122.248.192.0 Singapore
54.244.52.192 United States
46.137.224.0 Singapore
54.196.0.0 United States
54.148.0.0 United States
54.245.168.0 United States
174.129.0.0 United States
54.198.0.0 United States
50.16.0.0 United States
54.248.220.0 Japan
54.150.0.0 Japan
54.199.0.0 Japan
175.41.128.0 Singapore
54.250.253.192 Japan
50.18.0.0 United States
54.200.0.0 United States
54.151.0.0 United States
54.251.31.128 Singapore
175.41.192.0 Japan
54.202.0.0 United States
50.19.0.0 United States
54.252.79.128 Australia
54.151.128.0 Singapore
54.204.0.0 United States
176.32.64.0 Japan
54.252.254.192 Australia
50.112.0.0 United States
54.206.0.0 Australia
54.152.0.0 United States
54.255.254.192 Singapore
176.34.0.0 Japan
54.207.0.0 Brazil
52.0.0.0 United States
107.23.255.0 United States
54.153.0.0 United States
54.208.0.0 United States
176.34.32.0 Japan
176.34.159.192 Ireland
52.2.0.0 United States
54.210.0.0 United States
54.153.128.0 Australia
177.71.207.128 Brazil
176.34.64.0 Ireland
54.212.0.0 United States
52.4.0.0 United States
52.46.0.0 United States
54.154.0.0 Ireland
54.214.0.0 United States
176.34.128.0 Ireland
52.84.0.0 United States
52.8.0.0 United States
54.215.0.0 United States
52.219.40.0 Singapore
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Ficapy
# Create: '8/22/16'

import requests
import ipaddress
import asyncio
import aiohttp

ip_list = requests.get('https://ip-ranges.amazonaws.com/ip-ranges.json', timeout=4).json()

all = [next(iter(ipaddress.ip_network(i['ip_prefix']))).__str__() for i in ip_list['prefixes']]

sem = asyncio.Semaphore(30)
finish = 0
now_status = 'START'

session = aiohttp.ClientSession()


async def fetch(ip):
    global finish, now_status
    url = 'https://only-pass.com/api/ipgeo/{}/detail'.format(ip)
    async with sem:
        # async with aiohttp.ClientSession() as session:
        finish += 1
        for i in range(3):
            try:
                with aiohttp.Timeout(10):
                    async with session.get(url) as response:
                        response = await response.json()
                        now_status = response['country']
                        return ip, now_status
            except:
                pass
        return ip, 'ERROR'


async def progress():
    while 1:
        precent = int(100 * finish / len(all))
        print('\r{:<100}{precent}% {a}/{b} {now}'.format('=' * precent, a=finish, b=len(all), precent=precent,
                                                         now=now_status), end='')
        if len(all) == finish:
            session.close()
            break
        await asyncio.sleep(1)


tasks = []
for ip in all:
    tasks.append(fetch(ip))

loop = asyncio.get_event_loop()
ret, _ = loop.run_until_complete(asyncio.wait(tasks + [progress()]))
print('\n', end='')
for i in ret:
    try:
        print(' '.join(i.result()))
    except:
        pass