Google搜索嗅探器全局配置未定义
我用《Violent Python》这本书做了一个谷歌搜索嗅探器,但当我用 python sniffer.py -i mon0
运行这个代码时,它显示了以下内容:
traceback (most recent call last):
File "test.py, line 30, in <module>
main()
File "test.py", line 23, in main
conmf.iface = options.interface
NameError: global name 'conf' is not defined
我在Windows上使用的是最新版本的scapy,Python版本是2.7。哦,对了,我还稍微搞了一下安装,把文件夹移动到了正确的位置。
from scapy import *
import optparse
def findGoogle(pkt):
if pkt.haslayer(Raw):
payload = pkt .getLayer(Raw).load
if 'GET' in payload:
if 'google' in payload:
r = re.findall(r'(?!)\&q=(.*?)\&', payload)
if r:
search = r[0].split('&')[0]
search = search.replace('q=', '').replace('+', ' ').replace('%20', ' ')
print "Searched for" + search
def main():
parser = optparse.OptionParser('usage %prog -i '+ '<interface>')
parser.add_option('-i', dest='interface', type='string', help='specify interface to listen on')
(options, args) = parser.parse_args()
if options.interface == None:
print parser.usage
exit(0)
else:
conf.iface = options.interface
try:
print '[*]Starting Google Sniffer.'
sniff(filter='tcp port 80', prn=findGoogle)
except KeyboardInterrupt:
exit(0)
if __name__ == '__main__':
main()