Python 我如何找到周围的scapy无线网络?

Python 我如何找到周围的scapy无线网络?,python,wifi,wireless,scapy,Python,Wifi,Wireless,Scapy,我如何找到周围的scapy无线网络?如果我执行sniff()和如果pkt.haslayer(Dot11)然后执行如果pkt.info则收集它们,但速度非常慢,例如,我的Android手机只需几秒钟就可以完成,而这个脚本只需几分钟甚至更长的时间就可以完成…造成这种差异的原因是,您的手机通过向附近的任何接入点发送请求来主动寻找WiFi点-sniff正在监听任何通过的流量 您可能会发现: 特别选择您的网络适配器-这样您就不会嗅探所有适配器 进行一些挖掘,了解如何主动查询wifi网络,并使用sr处理此类

我如何找到周围的scapy无线网络?如果我执行
sniff()
如果pkt.haslayer(Dot11)
然后执行
如果pkt.info
则收集它们,但速度非常慢,例如,我的Android手机只需几秒钟就可以完成,而这个脚本只需几分钟甚至更长的时间就可以完成…

造成这种差异的原因是,您的手机通过向附近的任何接入点发送请求来主动寻找WiFi点-sniff正在监听任何通过的流量

您可能会发现:

  • 特别选择您的网络适配器-这样您就不会嗅探所有适配器
  • 进行一些挖掘,了解如何主动查询wifi网络,并使用
    sr
    处理此类数据包,阅读IEEE 802.11规范了解更多信息,我会特别查找“探测请求帧”
  • 关于如何从发送WiFi数据包的示例可能会很有帮助(不是我的代码,也不是我测试的):


    我曾经写过一个可以扫描无线网络的脚本。 它使用起来很简单:

    python rs.py mon0
    
    这里mon0是我们的接口。代码中有注释可以正确理解它

    #Implementation of a wireless scanner using Scapy library
    
    #!/usr/bin/env python
    # rs.py - Wireless AP scanner 
    #author rahil sharma
    # date 15/3/2013   @rs
    #usage python rs.py mon0
    #where mon0 is your monitoring interface
    #used this using my alfa card in bactrack
    import sys, os, signal 
    from multiprocessing import Process
    
    from scapy.all import *
    
    interface='' # monitor interface
    aps = {} # dictionary to store unique APs
    
    # process unique sniffed Beacons and ProbeResponses. 
    #haslayer packet has Dot11 layer present
    #ord() string to integer ex ord('a) will give 97
    def sniffAP(p):
        if ( (p.haslayer(Dot11Beacon))):
            ssid       = p[Dot11Elt].info
            bssid      = p[Dot11].addr3    
            channel    = int( ord(p[Dot11Elt:3].info))
            capability = p.sprintf("{Dot11Beacon:%Dot11Beacon.cap%}\
                    {Dot11ProbeResp:%Dot11ProbeResp.cap%}")
    
            # Check for encrypted networks
        #now we put Dot11Beacon.cap info in capability and using regular expression search inbuilt function in python we search for privacy if it is present then the network is encrypted
        #output of the above cap file is somewhat like this short-slot+DSSS-OFDM+res15+ESS
            if re.search("privacy", capability): enc = 'Y'
            else: enc  = 'N'
    
            # Save discovered AP
            aps[p[Dot11].addr3] = enc
    
            # Display discovered AP    
            print "%02d  %s  %s %s" % (int(channel), enc, bssid, ssid) 
    
    # Channel hopper - we are making a channel hopper because we want to scan the whole wireless spectrum.
    #first choose a random channel using randrange function
    #use system to run the shell command iw dev wlan0 set channel 1
    #exit when a keyboard interrupt is given CTrl+c
    def channel_hopper():
        while True:
            try:
                channel = random.randrange(1,15)
                os.system("iw dev %s set channel %d" % (interface, channel))
                time.sleep(1)
            except KeyboardInterrupt:
                break
                # Capture interrupt signal and cleanup before exiting
    #terminate is used to end the child process
    #before exiting the program we will be displaying number of aps found etc.
    #here Cntrl+c is used to 
    #signal_handler used to do clean up before the program exits
    def signal_handler(signal, frame):
        p.terminate()
        p.join()
    
        print "\n-=-=-=-=-=  STATISTICS =-=-=-=-=-=-"
        print "Total APs found: %d" % len(aps)
        print "Encrypted APs  : %d" % len([ap for ap in aps if aps[ap] =='Y'])
        print "Unencrypted APs: %d" % len([ap for ap in aps if aps[ap] =='N'])
    
        sys.exit(0)
    #use this for command line variables 
    #for checking the number of command line variables and if they are in right order
    if __name__ == "__main__":
        if len(sys.argv) != 2:
            print "Usage %s monitor_interface" % sys.argv[0]
            sys.exit(1)
    
        interface = sys.argv[1]
    #take mon0 as interface given in the fist command line variable
        # Print the program header
        print "-=-=-=-=-=-= rs_scan.py =-=-=-=-=-=-"
        print "CH ENC BSSID             SSID"
    
        # Start the channel hopper
        #In multiprocessing, processes are spawned by creating a Process object and then calling its start() method
        p = Process(target = channel_hopper)
        p.start()
    
        # Capture CTRL-C 
        #this will call the signal handler CTRL+C comes under the SIGINT
        signal.signal(signal.SIGINT, signal_handler)
    
        # Start the sniffer
        sniff(iface=interface,prn=sniffAP)
        #inbuit scapy function to start sniffing calls a function which defines the criteria and we need to give the interface`enter code here`
    

    我在
    airmon ng
    mon0
    上执行此操作
    sniff()
    
    #Implementation of a wireless scanner using Scapy library
    
    #!/usr/bin/env python
    # rs.py - Wireless AP scanner 
    #author rahil sharma
    # date 15/3/2013   @rs
    #usage python rs.py mon0
    #where mon0 is your monitoring interface
    #used this using my alfa card in bactrack
    import sys, os, signal 
    from multiprocessing import Process
    
    from scapy.all import *
    
    interface='' # monitor interface
    aps = {} # dictionary to store unique APs
    
    # process unique sniffed Beacons and ProbeResponses. 
    #haslayer packet has Dot11 layer present
    #ord() string to integer ex ord('a) will give 97
    def sniffAP(p):
        if ( (p.haslayer(Dot11Beacon))):
            ssid       = p[Dot11Elt].info
            bssid      = p[Dot11].addr3    
            channel    = int( ord(p[Dot11Elt:3].info))
            capability = p.sprintf("{Dot11Beacon:%Dot11Beacon.cap%}\
                    {Dot11ProbeResp:%Dot11ProbeResp.cap%}")
    
            # Check for encrypted networks
        #now we put Dot11Beacon.cap info in capability and using regular expression search inbuilt function in python we search for privacy if it is present then the network is encrypted
        #output of the above cap file is somewhat like this short-slot+DSSS-OFDM+res15+ESS
            if re.search("privacy", capability): enc = 'Y'
            else: enc  = 'N'
    
            # Save discovered AP
            aps[p[Dot11].addr3] = enc
    
            # Display discovered AP    
            print "%02d  %s  %s %s" % (int(channel), enc, bssid, ssid) 
    
    # Channel hopper - we are making a channel hopper because we want to scan the whole wireless spectrum.
    #first choose a random channel using randrange function
    #use system to run the shell command iw dev wlan0 set channel 1
    #exit when a keyboard interrupt is given CTrl+c
    def channel_hopper():
        while True:
            try:
                channel = random.randrange(1,15)
                os.system("iw dev %s set channel %d" % (interface, channel))
                time.sleep(1)
            except KeyboardInterrupt:
                break
                # Capture interrupt signal and cleanup before exiting
    #terminate is used to end the child process
    #before exiting the program we will be displaying number of aps found etc.
    #here Cntrl+c is used to 
    #signal_handler used to do clean up before the program exits
    def signal_handler(signal, frame):
        p.terminate()
        p.join()
    
        print "\n-=-=-=-=-=  STATISTICS =-=-=-=-=-=-"
        print "Total APs found: %d" % len(aps)
        print "Encrypted APs  : %d" % len([ap for ap in aps if aps[ap] =='Y'])
        print "Unencrypted APs: %d" % len([ap for ap in aps if aps[ap] =='N'])
    
        sys.exit(0)
    #use this for command line variables 
    #for checking the number of command line variables and if they are in right order
    if __name__ == "__main__":
        if len(sys.argv) != 2:
            print "Usage %s monitor_interface" % sys.argv[0]
            sys.exit(1)
    
        interface = sys.argv[1]
    #take mon0 as interface given in the fist command line variable
        # Print the program header
        print "-=-=-=-=-=-= rs_scan.py =-=-=-=-=-=-"
        print "CH ENC BSSID             SSID"
    
        # Start the channel hopper
        #In multiprocessing, processes are spawned by creating a Process object and then calling its start() method
        p = Process(target = channel_hopper)
        p.start()
    
        # Capture CTRL-C 
        #this will call the signal handler CTRL+C comes under the SIGINT
        signal.signal(signal.SIGINT, signal_handler)
    
        # Start the sniffer
        sniff(iface=interface,prn=sniffAP)
        #inbuit scapy function to start sniffing calls a function which defines the criteria and we need to give the interface`enter code here`