Bru*_*uno -2 python scapy pyshark
我正在尝试使用 pyshark 从远程计算机上本地托管的网站(测试目的)获取数据包。
这是我的代码:
import pyshark
def print_live_dns():
capture = pyshark.LiveCapture("wlan0")
for packet in capture:
# print(packet)
with open('packets.txt', 'a') as f:
f.write(str(packet))
if "DNS" in packet and not packet.dns.flags_response.int_value:
print(packet.dns.qry_name)
if __name__ == "__main__":
print_live_dns()
Run Code Online (Sandbox Code Playgroud)
使用此代码,我只能从 Internet 获取数据包。这不是我需要的。我如何实现这一目标?使用pyshark, scapy, nmap 等
您可以使用设置交集
>>> from functools import reduce
>>>
>>> my_list = [[2,3,5,6,7,8,9], [2,4,78,23,13,7], [3,2,5,98,23,1,34]]
>>> list(reduce(lambda x, y: set(x).intersection(set(y)), my_list))
[2]
>>>
Run Code Online (Sandbox Code Playgroud)