有懂Python的朋友没,帮忙解释下下面代码的意思。
#!/usr/bin/env python# Aug 19 2011# Copyleft@2011 Published Under BSD Lisense# Ronald Liu# lzsdc01@gmail.com# FYI http://lzsblog.appspot.com/%3Fp%3D291001#import sys,DNS,base64def splitList(txt): arr = txt.split("\n") l = [] for line in arr: if (not len(line)): #empty line continue if (line[0] == "!"): #Comment line continue elif(line[0:2] =="@@"):#Forbidding line continue elif(line.find("/")!=-1 or line.find("*")!=-1): #URL is ignored, only domains left continue #In this case, domain name is irrelevant to protocol(http or https) elif(line[0:2] =="||"): l.append(line[2:]) elif(line[0] == "."): l.append(line[1:]) else: l.append(line) return l #Decode and decorate the input stringf = open("gfwlist.txt","r")txt = f.read().replace("\n","")txt = base64.decodestring(txt)domains = splitList(txt)#Set default DNS serverDNSServer=['8.8.8.8']DNS.defaults['server']=DNSServerDNS.DiscoverNameServers()#These two varible are used to track the percentage of parsing process.l = 0a = len(domains)for line in domains: request=DNS.Request() try: result=request.req(name=line,qtype="A") except DNS.Base.DNSError: msg=line+"\tTime Out\n" else: if not len(result.answers): msg=line+"\tNo record\n" else: msg=line+ "\tBingo\n" for i in result.answers: if (i["typename"]=='A'): #Only A record is useful IP print line + " " + i["data"] print >> sys.stderr, line + msg, l*1.0/a, "%"
List<string> splitList(String txt) { String[] arr = txt.Split('\n'); List<string> l = new List<string>(); for (int i = 0; i < arr.Length; i++) { String line = arr[i]; if (line.Trim().Length == 0) { continue; } if (line.Substring(0, 1) == "!") { continue; } else if (line.Substring(0, 2) == "@@") { continue; } else if (line.IndexOf("/") != -1 || line.IndexOf("*") != -1) { continue; } else if (line.Substring(0, 2) == "||") { l.Add(line.Substring(2)); } else if (line.Substring(0, 1) == ".") { l.Add(line.Substring(1)); } else { l.Add(line); } } return l; } StreamReader f = new StreamReader(); String txt = File.ReadAllText(@"c:\gfwlist.txt").Replace("\n", ""); byte[] encodedDataAsBytes = System.Convert.FromBase64String(txt); txt = System.Text.Encoding.Unicode.GetString(encodedDataAsBytes); List<string> domains = splitList(txt); //下面对每一个地址进行查询,.NET好像没有现成的类,你可以参考 http://www.codeproject.com/KB/IP/DNS_NET_Resolver.aspx
[解决办法]
我刚开始学python,路过
[解决办法]
python新手路过学习ing......
[解决办法]
会python不会C#的路过,,,这个脚本功能估计是检查txt里的网址们有没有被墙.
[解决办法]
200分都没大神