用于 WiFi 的 Python 扫描
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39679421/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python scan for WiFi
提问by Luca dall'aglio
I was searching for a program that can scan for WiFi networks and print all of the SSIDs. I tried with scapy but I failed. I am using the pyCharm editor.
我正在寻找一个可以扫描 WiFi 网络并打印所有 SSID 的程序。我尝试过 scapy 但我失败了。我正在使用 pyCharm 编辑器。
I tried this code:
我试过这个代码:
from scapy.all import *
from scapy.layers.dot11 import Dot11
def packet_handler(pkt):
if pkt.haslayer(Dot11) and pkt.type == 2:
print(pkt.show())
scapy.sniff(iface="mon0", prn=packet_handler)
回答by Juggernaut
try pip install wifi
then for scanning use
pip install wifi
然后尝试扫描使用
from wifi import Cell, Scheme
Cell.all('wlan0')
This returns a list of Cell objects. Under the hood, this calls iwlist scan and parses the unfriendly output. Each cell object should have the following attributes: ssid, signal, quality and more. and for connecting use
这将返回一个 Cell 对象列表。在幕后,这会调用 iwlist 扫描并解析不友好的输出。每个单元格对象应具有以下属性:ssid、信号、质量等。和连接使用
cell = Cell.all('wlan0')[0]
scheme = Scheme.for_cell('wlan0', 'home', cell, passkey)
scheme.save()
scheme.activate()
scheme = Scheme.find('wlan0', 'home')
scheme.activate()
for more info goto https://wifi.readthedocs.io/en/latest/
有关更多信息,请转到https://wifi.readthedocs.io/en/latest/