我在获取数据包的DNS信息时遇到了一些pyshark问题。我正在使用python 3。
我的代码如下所示:
import pyshark
cap = pyshark.LiveCapture(interface="en1")
cap.sniff(timeout=5)
def print_dns_info(pkt):
if pkt.dns.qry_name:
print 'DNS Request from %s: %s' % (pkt.ip.src, pkt.dns.qry_name)
elif pkt.dns.resp_name:
print 'DNS Response from %s: %s' % (pkt.ip.src, pkt.dns.resp_name)
cap.apply_on_packets(print_dns_info, timeout=100)
错误看起来像这样:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
cap.apply_on_packets(print_dns_info, timeout=100)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyshark/capture/capture.py", line 201, in apply_on_packets
return self.eventloop.run_until_complete(coro)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/trollius/base_events.py", line 300, in run_until_complete
return future.result()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/trollius/futures.py", line 287, in result
raise self._exception
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/trollius/tasks.py", line 255, in _step
result = next(coro)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/trollius/tasks.py", line 424, in wait_for
raise Return(fut.result())
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/trollius/futures.py", line 287, in result
raise self._exception
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/trollius/tasks.py", line 251, in _step
result = coro.throw(exc)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyshark/capture/capture.py", line 215, in packets_from_tshark
packet_count=packet_count))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/trollius/tasks.py", line 253, in _step
result = coro.send(value)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyshark/capture/capture.py", line 238, in _go_through_packets_from_fd
packet_callback(packet)
File "<pyshell#5>", line 2, in print_dns_info
if pkt.dns.qry_name:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyshark/packet/packet.py", line 110, in __getattr__
raise AttributeError()
我甚至不打印任何有关数据包的信息,只打印错误。