这没多大帮助;发布你必须匹配的所有可能模式的例子(有点像开头的文档字符串,只有更多详细说明),否则你很难知道你是什么类型的代码尝试实现。 这是一种启发式方式,所以没有详尽的列表或硬性规则。 但是,我已在 http://bmsi.com/python/dynip.samp 附加DYN,例如当前算法将 分类为动态。 这是最后20个(其中我的主观判断是正确的): 65.112.76.15 usfshlxmx01.myreg.net 201.128.108.41 dsl-201-128-108-41.prod -infinitum.com.mx DYN 206.221.177.128 mail128.tanthillyingyang.com 68.234.254.147 68-234-254-147.stmnca.adelphia.net DYN 63.110.30.30 mx81.goingwiththe-flow.info 62.178.226.189 chello062178226189.14.15.vie.surfer.at DYN 80.179.107.85 80.179.107.85.ispeednet.net DYN 200.204.68.52 200-204-68-52 .dsl.telesp.net.br DYN 12.203.156.234 12-203-156-234.client.insightBB.com DYN 200.83.68.217 CM-lconC1-68 -217.cm.vtr.net DYN 81.57.1​​15.43 pauguste-3-81-57-115-43.fbx.proxad.net DYN 64.151.91.225 sv2a .entertainmentnewsclips.com 64.62.197.31 teenfreeway.sparklist.com 201.9.136.235 201009136235.user.veloxzone.com.br DYN 66.63 .187.91 91.asandox.com 83.69.188.198 st11h07.ptambre.com 66.192.199.217 66-192-199-217.pyramidcollection.org DYN 69.40.166.49 h49.166.40.69.ip.alltel.net DYN 203.89.206.62 smtp.immigrationexpert.ca 80.143.79.97 p508F4F61.dip0。 t-ipconnect.de DYN I have a function that recognizes PTR records for dynamic IPs. There isno hard and fast rule for this - every ISP does it differently, and maychange their policy at any time, and use different conventions indifferent places. Nevertheless, it is useful to apply stricterauthentication standards to incoming email when the PTR for the IPindicates a dynamic IP (namely, the PTR record is ignored since it doesn''tmean anything except to the ISP). This is because Windoze Zombies are thefavorite platform of spammers. Here is the very ugly code so far. It offends me to look at it, buthaven''t had any better ideas. I have lots of test data from mail logs. # examples we don''t yet recognize:## 1Cust65.tnt4.atl4.da.uu.net at (''67.192.40.65'', 4588)# 1Cust200.tnt8.bne1.da.uu.net at (''203.61.67.200'', 4144)# 1Cust141.tnt30.rtm1.nld.da.uu.net at (''213.116.154.141'', 2036)# user64.net2045.mo.sprint-hsd.net at (''67.77.185.64'', 3901)# wiley-268-8196.roadrunner.nf.net at (''205.251.174.46'', 4810)# 221.fib163.satnet.net at (''200.69.163.221'', 3301)# cpc2-ches1-4-0-cust8.lutn.cable.ntl.com at (''80.4.105.8'', 61099)# user239.res.openband.net at (''65.246.82.239'', 1392)# xdsl-2449.zgora.dialog.net.pl at (''81.168.237.145'', 1238)# spr1-runc1-4-0-cust25.bagu.broadband.ntl.com at (''80.5.10.25'', 1684)# user-0c6s7hv.cable.mindspring.com at (''24.110.30.63'', 3720)# user-0c8hvet.cable.mindspring.com at (''24.136.253.221'', 4529)# user-0cdf5j8.cable.mindspring.com at (''24.215.150.104'', 3783)# mmds-dhcp-11-143.plateautel.net at (''63.99.131.143'', 4858)# ca-santaanahub-cuda3-c6b-134.anhmca.adelphia.net at (''68.67.152.134'', 62047)# cbl-sd-02-79.aster.com.do at (''200.88.62.79'', 4153)# h105n6c2o912.bredband.skanova.com at (''213.67.33.105'', 3259) import re ip3 = re.compile(''([0-9]{1,3})[.x-]([0-9]{1,3})[.x-]([0-9]{1,3})'')rehmac = re.compile(''h[0-9a-f]{12}[.]|pcp[0-9]{6,10}pcs[.]|no-reverse|S[0-9a-f]{16}[.][a-z]{2}[.]'') def is_dynip(host,addr):"""Return True if hostname is for a dynamic ip.Examples: True"""if host.startswith(''['') and host.endswith('']''):return Trueif addr:if host.find(addr) >= 0: return Truea = addr.split(''.'')ia = map(int,a)m = ip3.search(host)if m:g = map(int,m.groups())if g == ia[1:] or g == ia[:3]: return Trueif g[0] == ia[3] and g[1:] == ia[:2]: return Trueg.reverse()if g == ia[1:] or g == ia[:3]: return Trueif rehmac.search(host): return Trueif host.find("%s." % ''-''.join(a[2:])) >= 0: return Trueif host.find("w%s." % ''-''.join(a[:2])) >= 0: return Trueif host.find("dsl%s-" % ''-''.join(a[:2])) >= 0: return Trueif host.find(''''.join(a[:3])) >= 0: return Trueif host.find(''''.join(a[1:])) >= 0: return Truex = "%02x%02x%02x%02x" % tuple(ia)if host.lower().find(x) >= 0: return Truez = [n.zfill(3) for n in a]if host.find(''-''.join(z)) >= 0: return Trueif host.find("-%s." % ''-''.join(z[2:])) >= 0: return Trueif host.find("%s." % ''''.join(z[2:])) >= 0: return Trueif host.find(''''.join(z)) >= 0: return Truea.reverse()if host.find("%s." % ''-''.join(a[:2])) >= 0: return Trueif host.find("%s." % ''.''.join(a[:2])) >= 0: return Trueif host.find("%s." % a[0]) >= 0 and \host.find(''.adsl.'') > 0 or host.find(''.dial-up.'') > 0: return Truereturn False if __name__ == ''__main__'':import fileinputfor ln in fileinput.input():a = ln.split()if len(a) == 2:ip,host = aif host.startswith(''['') and host.endswith('']''):continue # no PTRif is_dynip(host,ip):print ip,host 解决方案 This doesn''t help much; post example of all the possible patterns you haveto match (kind of like the docstring at the beginning, only moreelaborate), otherwise it''s hard to know what kind of code you''re trying toimplement.--Mitja This doesn''t help much; post example of all the possible patterns you have to match (kind of like the docstring at the beginning, only more elaborate), otherwise it''s hard to know what kind of code you''re trying to implement. This is a heuristic, so there is no exhaustive list or hard rule.However, I have posted 23K+ examples at http://bmsi.com/python/dynip.sampwith DYN appended for examples which the current algorithm classifiesas dynamic. Here are the last 20 (which my subjective judgement says are correct): 65.112.76.15 usfshlxmx01.myreg.net201.128.108.41 dsl-201-128-108-41.prod-infinitum.com.mx DYN206.221.177.128 mail128.tanthillyingyang.com68.234.254.147 68-234-254-147.stmnca.adelphia.net DYN63.110.30.30 mx81.goingwiththe-flow.info62.178.226.189 chello062178226189.14.15.vie.surfer.at DYN80.179.107.85 80.179.107.85.ispeednet.net DYN200.204.68.52 200-204-68-52.dsl.telesp.net.br DYN12.203.156.234 12-203-156-234.client.insightBB.com DYN200.83.68.217 CM-lconC1-68-217.cm.vtr.net DYN81.57.115.43 pauguste-3-81-57-115-43.fbx.proxad.net DYN64.151.91.225 sv2a.entertainmentnewsclips.com64.62.197.31 teenfreeway.sparklist.com201.9.136.235 201009136235.user.veloxzone.com.br DYN66.63.187.91 91.asandox.com83.69.188.198 st11h07.ptambre.com66.192.199.217 66-192-199-217.pyramidcollection.org DYN69.40.166.49 h49.166.40.69.ip.alltel.net DYN203.89.206.62 smtp.immigrationexpert.ca80.143.79.97 p508F4F61.dip0.t-ipconnect.de DYN 这篇关于帮助美化丑陋的启发式代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 16:01