我在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
我在使用python 2.7的Windows上使用最新版本的scapy。哦,我也通过将文件夹移动到正确的位置来安装它。
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()
答案 0 :(得分:0)
您似乎错误地输入了一行while transcribing it,
from scapy import *
应该阅读
from scapy.all import *
scapy
文档有点稀疏,但显然conf
已在其中定义。
编辑:深入了解源代码,看起来像all.py
导入config.py
,其中包含
conf=Conf()
所以这绝对是罪魁祸首。