python hosts

怒了,自己写个python程序来更新hosts。先占个坑,晚点来填。

 

*****************************我是时光长河的分界线***********T_T***************************************

 

千年前挖下的坑,今天终于填了=。=。。。

 

本来老抽风的google ip,后来从霓虹国那边拿到了个稳定IP用了两三个月,就一直找不出动力来研究python的网络编程(T_T)

今天早上终于到了图穷匕见,真相大白,水落石出,东窗事发,原形毕露(好坑的百度近义词搜索=。=。。。就装一下逼都不肯帮忙。。。)的时候,我撸起袖管(此处该响起国歌,"起来,不愿做奴隶的人们!"),一不做,而不休,写出了个小脚本来找可用google IP  :P

 

思路很简单,就是随机试google在全世界各地的IP地址=。=直到成功。所以能否快速找到“梯子”,还是比较看人品的。另外,没考虑进IPV6情况。

 

上代码:

# -*- coding: utf-8 -*-
#!/usr/bin/env python
"""
This script is used to find out accessible google ip
For easy, every ip range i only consider about the first 255 address
F**k GFW

Licence:
            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                    Version 2, December 2004

 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as long
 as the name is changed.

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. You just DO WHAT THE FUCK YOU WANT TO.

"""
__author__='alex<alexande2008@gmail.com'

import urllib2 as ul
import random
import sys

ip_ranges=[]
with open('google_ip_ranges','r') as g:
    for line in g:
        if str.isdigit(line[0]):
            ip_ranges.append(line.split(' - ')[0])

def replace(li,i,new):
    li[i]=new
    return li

#program does NOT stop until find out a accessible ip
while 1:
    one=random.choice(ip_ranges)
    #only try 5 times in one range
    for i in range(10):
        url='http://'+'.'.join(replace(one.split('.'),3,str(random.randint(0,255))))
        try:
            res=''
            res=ul.urlopen(url,timeout=3)
            if res.read()!='':
                print 'Bingo! '+url.strip('http://')
                sys.exit('Enjoy:)')
        except Exception:
            print ':( missed: '+url
            continue

 

代码极端简单,不说废话了。

再上下google在全球的域名段,也就是脚本里的 google_ip_ranges 文件内容:

google 中国(China) IP地址列表 (PING: ~30ms)
203.208.32.0 - 203.208.62.255
--------------------------------------------
google 香港(HongKong) IP地址列表
58.176.217.0 - 58.176.217.255
113.197.105.0 - 113.197.105.255
218.189.25.0 - 218.189.25.255
218.253.0.0 - 218.253.0.255

--------------------------------------------
google 台湾(TaiWan) IP地址列表
60.199.175.0 - 60.199.175.255 
61.219.131.0 - 60.219.131.255
123.205.250.0 - 123.205.251.255
163.28.83.0 - 163.28.83.255
163.28.116.0 - 163.28.116.255
202.39.143.0 - 202.39.143.255
203.211.0.0 - 203.211.0.255
203.66.124.0 - 203.66.124.255
210.61.221.0 - 210.61.221.255
--------------------------------------------
google 美国(American) IP地址列表(PING:~300ms)
4.3.2.0 - 4.3.2.255
8.8.4.0 - 8.8.4.255
8.8.8.0 - 8.8.8.255
12.216.80.0 - 12.216.80.255
12.234.149.240 - 12.234.149.247
63.158.137.224 - 63.158.137.231
63.237.119.112 - 63.237.119.119
64.41.221.192 - 64.41.221.207
64.68.64.64 - 64.68.64.127
64.68.80.0 - 64.68.95.255
64.233.160.0 - 64.233.191.255
66.102.0.0 - 66.102.15.255
66.249.64.0 - 66.249.95.255
67.148.177.136 - 67.148.177.143
70.32.128.0 - 70.32.159.255
70.90.219.48 - 70.90.219.55
70.90.219.72 - 70.90.219.79
72.14.192.0 - 72.14.255.255
74.125.0.0 - 74.125.255.255
108.170.192.0 - 108.170.255.255
108.177.0.0 - 108.177.127.255
142.250.0.0 - 142.251.255.255
172.217.0.0 - 172.217.255.255
172.253.0.0 - 172.253.255.255
173.194.0.0 - 173.194.255.255
192.178.0.0 - 192.179.255.255
198.108.100.192 - 198.108.100.207
207.223.160.0 - 207.223.175.255
207.225.234.32 - 207.225.234.39
208.46.199.160 - 208.46.199.167
208.117.224.0 - 208.117.255.255
209.85.128.0 - 209.85.255.255
209.185.108.128 - 209.185.108.255
216.33.229.144 - 216.33.229.151
216.33.229.160 - 216.33.229.167
216.58.192.0 - 216.58.223.255
216.109.75.80 - 216.109.75.95
216.239.32.0 - 216.239.63.255
--------------------------------------------
google 俄罗斯(Russia) IP地址列表(PING:~300ms)
46.61.155.0 - 46.61.155.255
89.175.35.32 - 89.175.35.47
89.175.162.48 - 89.175.162.55
89.175.165.0 - 89.175.165.15
95.167.107.32 - 95.167.107.63
178.45.250.0 - 178.45.251.255
213.248.112.64 - 213.248.112.127
--------------------------------------------
google 芬兰(Finland)  IP地址列表
80.239.229.192 - 80.239.229.255
--------------------------------------------
google 丹麦(Denmark)  IP地址列表
62.116.207.0 - 62.116.207.255
80.239.174.64 - 80.239.174.127
--------------------------------------------
google 德国(Germany)  IP地址列表
80.239.142.192 - 80.239.142.255
--------------------------------------------
google 法国(France)  IP地址列表
80.239.168.192 - 80.239.168.255
--------------------------------------------
google 罗马尼亚(Romania)  IP地址列表
46.108.1.128 - 46.108.1.191
--------------------------------------------
google 土耳其(Turkey)
92.45.86.16 - 92.45.86.31
--------------------------------------------
google 爱尔兰(Ireland)  IP地址列表
193.120.166.64 - 193.120.166.127
--------------------------------------------
google 乌克兰(Ukraine)  IP地址列表
194.44.4.0 - 194.44.4.255
--------------------------------------------
google 以色列(Israel)  IP地址列表
212.179.82.48 - 212.179.82.63
--------------------------------------------
google 埃及(Egypt) IP地址列表
197.199.253.0~197.199.254.255
--------------------------------------------
google 新加坡(Singapore) IP地址列表
203.116.165.0 - 203.116.165.255
203.117.34.0 - 203.117.34.255
--------------------------------------------
google 保加利亚(Bulgaria) IP地址列表
93.123.23.0 - 93.123.23.255
--------------------------------------------
google 捷克(Czech) IP地址列表
95.173.210.0 - 95.173.210.255
62.197.198.208 - 62.197.198.251
-------------------------------------------- 
google 冰岛(IceLand) IP地址列表
149.126.86.0 - 149.126.86.255
--------------------------------------------
google 印度尼西亚(Indonesia) IP地址列表
111.92.162.0 - 111.92.162.255
--------------------------------------------
google 伊拉克(Iraq) IP地址列表
46.61.155.0 - 46.61.155.255
62.201.216.0 - 62.201.216.255
--------------------------------------------
google 加拿大(Canada)  IP地址列表
199.87.241.32 - 199.87.241.63
--------------------------------------------
google 瑞典(Sweden)  IP地址列表
83.140.66.0 - 83.140.66.255
195.100.224.112 - 195.100.224.127
--------------------------------------------
google 英国(UK)  IP地址列表
87.245.196.0 - 87.245.196.255
195.50.84.192 - 195.50.84.255
213.155.151.128 - 213.155.151.191
213.253.9.128 - 213.253.9.191
217.163.1.64 - 217.163.1.127
--------------------------------------------
google 意大利(Italy)  IP地址列表
213.242.89.64 - 213.242.89.127
--------------------------------------------
google 肯尼亚(Kenya)  IP地址列表
41.84.159.0 - 41.84.159.255
196.3.58.0 - 196.3.58.255
--------------------------------------------
google 日本(Japan)  IP地址列表(PING:~100ms)
59.190.145.0 - 59.190.145.255
121.83.201.0 - 121.83.201.255
218.176.242.0 - 218.176.242.255
--------------------------------------------
google 印度(India)  IP地址列表
113.197.107.0 - 113.197.107.255
--------------------------------------------
google 泰国(Thailand)  IP地址列表
1.179.248.0 - 1.179.255.255
61.19.1.0 - 61.19.2.255
118.174.24.0 - 118.174.27.255
--------------------------------------------
google 菲律宾(Philippines) IP地址列表
103.25.178.0 - 103.25.178.255
--------------------------------------------
google 韩国(Korea)  IP地址列表
59.18.44.0 - 59.18.44.255
121.78.74.0 - 121.78.74.255
--------------------------------------------
google 荷兰(Holland) IP地址列表
88.159.13.0 - 88.159.13.255
--------------------------------------------
google 毛里求斯(Mauritius)  IP地址列表
41.206.96.0 - 41.206.96.255
--------------------------------------------
google 澳大利亚(Australia)  IP地址列表
113.197.104.0 - 113.197.107.255
119.161.83.0 - 119.161.83.255
--------------------------------------------
google 挪威(Norway)  IP地址列表
193.90.147.0 - 193.90.147.255
--------------------------------------------
google 沙特阿拉伯王国(Saudi Arabia)
84.235.77.0 - 84.235.77.255
--------------------------------------------
google 塞尔维亚(Serbia)  IP地址列表
79.101.111.0 - 79.101.111.255
213.240.44.0 - 213.240.44.31
--------------------------------------------
google 新西兰(New Zealand) IP地址列表
203.97.30.0 - 203.97.30.255
View Code

 

Enjoy.

posted on 2015-01-11 16:49  alex_wood  阅读(382)  评论(0编辑  收藏  举报