python scapy sniff timeout_Python/scapy:sniff()函数在按CTRLC时不中断

我正在编写一个脚本,显示所有可用的WiFi网络。我用scapy来做这个。在

我想在按下CTRL-C时结束脚本,但是按下后什么都没有发生,脚本继续搜索WiFi网络。在

我读到它可能是由threading引起的。但我一根线也没开始。即使在按下CTRL-BREAK之后,程序仍然继续。在def PcktHandler(pckt):

global APs

try:

if pckt.haslayer(Dot11):

if pckt.type == 0 and pckt.subtype == 8:

if pckt.addr2 not in APs:

APs[pckt.addr2] = pckt.info

output_aps(pckt.addr2, pckt.info, on_channel)

except keyboardInterrupt:

os._exit

def output_aps(bssid, essid, channel):

ch_space = 3

if len(str(channel)) == 1:

ch_space = 4

print(str(bssid).upper()+' '*3+'| '+str(channel)+' '*ch_space+'| '+str(essid))

# scanning for networks

def scan():

global on_channel #-> channel currently on

print('[*] Scanning for WiFi-Networks...\n')

print('BSSID' + ' '*17 + 'CH' + ' '*5 + 'ESSID')

while on_channel < 15:

# channel hopping and sniffing

try:

os.system('iwconfig ' + iface + ' channel ' + str(on_channel))

except (OSError):

print('[-] Invalid interface.')

try:

sniff(iface='wlan0mon', prn=PcktHandler, count=10, timeout=3)

except KeyboardInterrupt:

os._exit

on_channel += 1

if on_channel >= 14:

on_channel = 1

if __name__ == '__main__':

args = argument_parser()

APs = {}

on_channel = 1

if args.interface:

iface = args.interface

conf.iface = iface

if args.scan:

scan()

else:

print('[!] Select an interface.')

希望有解决办法!

谢谢你的帮助!在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值