用 Flora_Pac.py 生成自动翻墙的 pac 文件
来源:互联网 发布:ip地址定位软件 编辑:程序博客网 时间:2024/05/29 17:53
#!/usr/bin/env python## Flora_Pac by @leaskh# www.leaskh.com, i@leaskh.com## based on chnroutes project (by Numb.Majority@gmail.com)#import reimport urllib2import argparseimport mathdef generate_pac(proxy): results = fetch_ip_data() pacfile = 'flora_pac.pac' rfile = open(pacfile, 'w') strLines = ( "// Flora_Pac by @leaskh" "\n// www.leaskh.com, i@leaskh.com" "\n" "\nfunction FindProxyForURL(url, host)" "\n{" "\n" "\n var list = [" ) intLines = 0 for ip,mask,_ in results: if intLines > 0: strLines = strLines + ',' intLines = intLines + 1 strLines = strLines + "\n ['%s', '%s']"%(ip, mask) strLines = strLines + ( "\n ];" "\n" "\n var ip = dnsResolve(host);" "\n" "\n for (var i in list) {" "\n if (isInNet(ip, list[i][0], list[i][1])) {" "\n return 'DIRECT';" "\n }" "\n }" "\n" "\n return '%s';" "\n" "\n}" "\n"%(proxy) ) rfile.write(strLines) rfile.close() print ("Rules: %d items.\n" "Usage: Use the newly created %s as your web browser's automatic " "proxy configuration (.pac) file."%(intLines, pacfile))def fetch_ip_data(): #fetch data from apnic print "Fetching data from apnic.net, it might take a few minutes, please wait..." url=r'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' data=urllib2.urlopen(url).read() cnregex=re.compile(r'apnic\|cn\|ipv4\|[0-9\.]+\|[0-9]+\|[0-9]+\|a.*',re.IGNORECASE) cndata=cnregex.findall(data) results=[] for item in cndata: unit_items=item.split('|') starting_ip=unit_items[3] num_ip=int(unit_items[4]) imask=0xffffffff^(num_ip-1) #convert to string imask=hex(imask)[2:] mask=[0]*4 mask[0]=imask[0:2] mask[1]=imask[2:4] mask[2]=imask[4:6] mask[3]=imask[6:8] #convert str to int mask=[ int(i,16 ) for i in mask] mask="%d.%d.%d.%d"%tuple(mask) #mask in *nix format mask2=32-int(math.log(num_ip,2)) results.append((starting_ip,mask,mask2)) return resultsif __name__=='__main__': parser=argparse.ArgumentParser(description="Generate proxy auto-config rules.") parser.add_argument('-x', '--proxy', dest = 'proxy', default = 'SOCKS 127.0.0.1:8964', nargs = '?', help = "Proxy Server, examples: " "SOCKS 127.0.0.1:8964; " "SOCKS5 127.0.0.1:8964; " "PROXY 127.0.0.1:8964") args = parser.parse_args() generate_pac(args.proxy)
####### 获得帮助:$ python flora_pac.py -husage: flora_pac.py [-h] [-x [PROXY]]Generate proxy auto-config rules.optional arguments: -h, --help show this help message and exit -x [PROXY], --proxy [PROXY] Proxy Server, examples: SOCKS 127.0.0.1:8964; SOCKS5 127.0.0.1:8964; PROXY 127.0.0.1:8964####### 生成 pac 文件,国外 IP 通过代理 SOCKS 代理 127.0.0.1:8964 访问:$ python flora_pac.py -x 'SOCKS 127.0.0.1:8964'Fetching data from apnic.net, it might take a few minutes, please wait...Rules: 3460 items.Usage: Use the newly created flora_pac.pac as your web browser's automatic proxy configuration (.pac) file.####### 生成 pac 文件,国外 IP 通过代理 HTTP 代理 127.0.0.1:8964 访问:$ python flora_pac.py -x 'PROXY 127.0.0.1:8964'Fetching data from apnic.net, it might take a few minutes, please wait...Rules: 3460 items.Usage: Use the newly created flora_pac.pac as your web browser's automatic proxy configuration (.pac) file.
0 0
- 用 Flora_Pac.py 生成自动翻墙的 pac 文件
- 如何自动生成setup.py文件
- PAC自动代理文件格式,教你如何写PAC文件
- 浅析PAC,教你动手修改你的PAC文件及user-rule文件实现自动代理
- 自定义PAC文件实现代理自动配置
- 怎样将写好的.py文件用cxfreeze生成exe可执行文件
- python的.py文件如何生成
- 调试自动代理脚本pac的方法
- PAC文件
- python的py文件生成单个pyc文件
- vc自动生成的文件
- PAC文件详解
- pac文件示例
- .py文件的执行
- IE自动配置脚本(PAC)
- 代理自动配置PAC学习
- 利用爬虫抓取文件翻墙的问题
- 自动翻屏的js程序
- android学习笔记18 - activity反馈:startActivityForResult、setResut和onActivityResult
- session/application/bean的学习
- 4、对正投影相机以及透视相机的使用,以及对场景通过鼠标控制大小以及旋转
- LSA概述与实例
- latex如何添加文本框
- 用 Flora_Pac.py 生成自动翻墙的 pac 文件
- 无线网卡监听模式
- Dos命令制作一句话木马
- 网口扫盲一:网卡初步认识
- Jquery 实现div拖拽
- activemq的插件编写
- HFJG-3系列高压发泡机
- unity基础
- iOS9 HTTPS请求: AFNetworking2安全的使用自签证书访问HTTPS