当前位置: 首页>>代码示例>>Python>>正文


Python sendrecv.sniff函数代码示例

本文整理汇总了Python中scapy.sendrecv.sniff函数的典型用法代码示例。如果您正苦于以下问题:Python sniff函数的具体用法?Python sniff怎么用?Python sniff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了sniff函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

    def run(self):
        pfilter = 'port %d' % self._port
        try:
            kwargs = {
                'filter': pfilter,
                'store': 0,
                'prn': self._handle_packet,
                'iface': self._iface,
                'stop_filter': lambda p: self._wants_stop,
                }

            if self._offline:
                kwargs['offline'] = self._offline

            sniff(**kwargs)
        except Exception as ex:
            if 'Not a pcap capture file' in str(ex):
                print('%s is not a valid pcap file' % self._offline)
                return
            print('Error: %s: %s (device: %s)' % (ex, traceback.format_exc(), self._iface))
        finally:
            if self._offline:
                # drain dispatcher
                while not self._dispatcher.empty:
                    time.sleep(0.1)
开发者ID:myjfm,项目名称:thrift-tools,代码行数:25,代码来源:sniffer.py

示例2: pull_data

def pull_data():
    """
    Obtiene datos de la interfaz. Deberia delegar el pedido al manager de datos
    """
    sniff(iface = IFACE,
          prn = lambda package: process_sniffed_package(package, persist_bssid_ssids),
          lfilter = lambda package: package.haslayer(Dot11Elt) )
开发者ID:FomkaV,项目名称:wifi-arsenal,代码行数:7,代码来源:wipi.py

示例3: run

 def run(self):
   try:
     log.info("Setting filter: %s", self.config.filter)
     if self.config.iface == "any":  # pragma: no cover
       sniff(
         filter=self.config.filter,
         store=0,
         prn=self.handle_packet,
         stop_filter=self.wants_stop
       )
     else:
       sniff(
         filter=self.config.filter,
         store=0,
         prn=self.handle_packet,
         iface=self.config.iface,
         stop_filter=self.wants_stop
       )
   except socket.error as ex:
     if self._error_to_stderr:
       sys.stderr.write("Error: %s, device: %s\n" % (ex, self.config.iface))
     else:
       log.error("Error: %s, device: %s", ex, self.config.iface)
   finally:
     log.info("The sniff loop exited")
     os.kill(os.getpid(), signal.SIGINT)
开发者ID:bbuneci,项目名称:zktraffic,代码行数:26,代码来源:sniffer.py

示例4: run

	def run(self):
		"""
		This is the thread routine that handles probe requests and sends
		probe responses when appropriate.
		"""
		while not self.__shutdown__:
			sniff(iface=self.interface, store=0, timeout=RESPONSE_TIMEOUT, stop_filter=self.__stopfilter__)
			if self.lastpacket:
				if self.lastpacket.haslayer(Dot11ProbeReq):
					ssid = None
					tmp = self.lastpacket.getlayer(Dot11ProbeReq)
					while tmp:
						tmp = tmp.payload
						if tmp.fields['ID'] == 0:
							ssid = tmp.info
							break
					if ssid is None:
						continue
					elif ssid == '' and self.essid:
						ssid = self.essid
					if self.essid is None or self.essid == ssid:
						self.probe_response_template.getlayer(Dot11).addr1 = get_source(self.lastpacket)
						self.probe_response_template.getlayer(Dot11Elt).info = ssid
						sendp(self.probe_response_template, iface=self.interface, verbose=False)
					self.lastpacket = None
					continue
				clientMAC = get_source(self.lastpacket)
				if not self.client_queue.full():
					self.client_queue.put(clientMAC, False)
				self.lastpacket = None
				continue
开发者ID:securestate,项目名称:eapeak,代码行数:31,代码来源:inject.py

示例5: get_rsn_information

	def get_rsn_information(self, essid):
		rsnInfo = None
		sendp(
			RadioTap()/
			Dot11(addr1=self.bssid, addr2=self.source_mac, addr3=self.bssid, SC=self.__fixSC__(), subtype=4)/
			Dot11ProbeReq()/
			Dot11Elt(ID=0, info=essid)/
			Dot11Elt(ID=1, info='\x82\x84\x0b\x16\x24\x30\x48\x6c')/
			Dot11Elt(ID=50, info='\x0c\x12\x18\x60'),
			iface=self.interface,
			verbose=False
		)
		self.sequence += 1
		sniff(iface=self.interface, store=0, timeout=self.timeout, stop_filter=self.__stopfilter__)
		if self.lastpacket is None or not self.lastpacket.haslayer(Dot11ProbeResp):
			return None
		probeResp = self.lastpacket.getlayer(Dot11ProbeResp)
		tmp = probeResp.getlayer(Dot11Elt)
		while tmp:
			if tmp.fields.get('ID') == 48:
				rsnInfo = tmp
				break
			else:
				tmp = tmp.payload
		if rsnInfo is None:
			rsnInfo = ''  # Did not find rsnInfo in probe response.
		else:
			rsnInfo = build_rsn_data(parse_rsn_data(rsnInfo.info))
			rsnInfo = '\x30' + chr(len(rsnInfo)) + rsnInfo
		return rsnInfo
开发者ID:securestate,项目名称:eapeak,代码行数:30,代码来源:inject.py

示例6: voip_play2

def voip_play2(s1,**kargs):
    """
    Same than voip_play, but will play
    both incoming and outcoming packets.
    The sound will surely suffer distortion.

    Only supports sniffing.

    .. seealso:: voip_play
    to play only incoming packets.
    """
    dsp,rd = os.popen2(sox_base % "-c 2")
    global x1, x2
    x1 = ""
    x2 = ""
    def play(pkt):
        global x1, x2
        if not pkt:
            return 
        if not pkt.haslayer(UDP) or not pkt.haslayer(IP):
            return 
        ip=pkt.getlayer(IP)
        if s1 in [ip.src, ip.dst]:
            if ip.dst == s1:
                x1 += pkt.getlayer(conf.raw_layer).load[12:]
            else:
                x2 += pkt.getlayer(conf.raw_layer).load[12:]
            x1, x2, r = _merge_sound_bytes(x1, x2)
            dsp.write(r)
            
    sniff(store=0, prn=play, **kargs)
开发者ID:thibaultdelmas,项目名称:scapy,代码行数:31,代码来源:voip.py

示例7: main

def main():
    options = parse_options()

    if options.verbose:
        logging.basicConfig(level=logging.DEBUG)

    parser = DiagParser(options)

    def print_interfaces():
        print("[*] Available interfaces:")
        for iface in get_if_list():
            print("[ ]\t%s (%s)" % (iface, get_if_addr(iface)))

    if not (options.interface or options.pcap):
        print("[*] Must provide a pcap file or an interface to sniff on")
        print_interfaces()
        return

    if options.pcap:
        print("[*] Parsing pcap file (%s)" % options.pcap)
    else:
        if options.interface not in get_if_list():
            print("[*] Invalid interface '%s'" % options.interface)
            print_interfaces()
            return
        print("[*] Listening on interface (%s)" % options.interface)

    try:
        sniff(iface=options.interface, offline=options.pcap, prn=parser.parse_packet, store=0)
    except KeyboardInterrupt:
        pass

    print("[*] Finished parsing/sniffing")
    parser.reassemble()
开发者ID:CoreSecurity,项目名称:pysap,代码行数:34,代码来源:diag_capturer.py

示例8: voip_play3

def voip_play3(lst=None, **kargs):
    """Same than voip_play, but made to
    read and play VoIP RTP packets, without
    checking IP.

    .. seealso:: voip_play
    for basic VoIP packets
    """
    dsp, rd = os.popen2(sox_base % "")

    def play(pkt, dsp=dsp):
        if pkt and pkt.haslayer(UDP) and pkt.haslayer(RTP):
            dsp.write(pkt.getlayer(RTP).load)
    try:
        if lst is None:
            sniff(store=0, prn=play, **kargs)
        else:
            for p in lst:
                play(p)
    finally:
        try:
            dsp.close()
            rd.close()
        except:
            pass
开发者ID:plorinquer,项目名称:scapy,代码行数:25,代码来源:voip.py

示例9: run

 def run(self):
   try:
     log.info("Setting filter: %s", self.config.filter)
     sniff(filter=self.config.filter, store=0, prn=self.handle_packet, iface=self.config.iface)
   finally:
     log.info("The sniff loop exited")
     os.kill(os.getpid(), signal.SIGINT)
开发者ID:phobos182,项目名称:zktraffic,代码行数:7,代码来源:sniffer.py

示例10: getRSNInformation

	def getRSNInformation(self, essid):
		sendp(	RadioTap()/
				Dot11(addr1=self.bssid, addr2=self.source_mac, addr3=self.bssid, SC=self.__unfuckupSC__(), subtype=4)/
				Dot11ProbeReq()/
				Dot11Elt(ID=0, info=essid)/
				Dot11Elt(ID=1, info='\x82\x84\x0b\x16\x24\x30\x48\x6c')/
				Dot11Elt(ID=50, info='\x0c\x12\x18\x60'),
				iface=self.interface, verbose=False)
		self.sequence += 1
		sniff(iface=self.interface, store=0, timeout=self.timeout, stop_filter=self.__stopfilter__)
		if self.lastpacket == None or not self.lastpacket.haslayer('Dot11ProbeResp'):
			return None
		probeResp = self.lastpacket.getlayer(Dot11ProbeResp)
		tmp = probeResp.getlayer(Dot11Elt)
		while tmp:
			if tmp.fields.get('ID') == 48:
				rsnInfo = tmp
				break
			else:
				tmp = tmp.payload
		if rsnInfo == None:
			rsnInfo = ''	# we didn't find it in the probe response, so we'll return an empty string
		else:
			rsnInfo = parseRSNData(rsnInfo.info)
			rsnInfo = buildRSNData(rsnInfo)
			rsnInfo = '\x30' + chr(len(rsnInfo)) + rsnInfo
		return rsnInfo
开发者ID:FomkaV,项目名称:wifi-arsenal,代码行数:27,代码来源:inject.py

示例11: voip_play2

def voip_play2(s1,**kargs):
    dsp,rd = os.popen2("sox -t .ul -c 2 - -t ossdsp /dev/dsp")
    def play(pkt,last=[]):
        if not pkt:
            return 
        if not pkt.haslayer(UDP):
            return 
        ip=pkt.getlayer(IP)
        if s1 in [ip.src, ip.dst]:
            if not last:
                last.append(pkt)
                return
            load=last.pop()
            x1 = load.load[12:]
#            c1.write(load.load[12:])
            if load.getlayer(IP).src == ip.src:
                x2 = ""
#                c2.write("\x00"*len(load.load[12:]))
                last.append(pkt)
            else:
                x2 = pkt.load[:12]
#                c2.write(pkt.load[12:])
            dsp.write(merge(x1,x2))
            
    sniff(store=0, prn=play, **kargs)
开发者ID:0x90,项目名称:scapy-osx,代码行数:25,代码来源:voip.py

示例12: recv

	def recv(self, bufferlen=0):
		"""
		Read a frame and return the information above the Dot11 layer.
		"""
		sniff(iface=self.interface, store=0, timeout=self.timeout, stop_filter=self.__stopfilter__)
		if self.lastpacket:
			return self.lastpacket
		else:
			return None
开发者ID:securestate,项目名称:eapeak,代码行数:9,代码来源:inject.py

示例13: run

 def run(self):
   pfilter = "port %d" % self._port
   try:
     log.info("Setting filter: %s", pfilter)
     sniff(filter=pfilter, store=0, prn=self.handle_packet, iface=self._iface)
   except socket.error as ex:
     log.error("Error: %s, device: %s", ex, self._iface)
   finally:
     log.info("The sniff loop exited")
     os.kill(os.getpid(), signal.SIGINT)
开发者ID:aalzabarah,项目名称:zktraffic,代码行数:10,代码来源:sniffer.py

示例14: run

 def run(self):
   pfilter = "port %d" % self._port
   try:
     if self._iface == "any":
       sniff(filter=pfilter, store=0, prn=self.handle_packet)
     else:
       sniff(filter=pfilter, store=0, prn=self.handle_packet, iface=self._iface)
   except socket.error as ex:
     sys.stderr.write("Error: %s, device: %s\n" % (ex, self._iface))
   finally:
     os.kill(os.getpid(), signal.SIGINT)
开发者ID:narayana1208,项目名称:zktraffic,代码行数:11,代码来源:sniffer.py

示例15: run

 def run(self):
   try:
     log.info("Setting filter: %s", self.config.filter)
     if self.config.iface == "any":
       sniff(filter=self.config.filter, store=0, prn=self.handle_packet)
     else:
       sniff(filter=self.config.filter, store=0, prn=self.handle_packet, iface=self.config.iface)
   except socket.error as ex:
     log.error("Error: %s, device: %s", ex, self.config.iface)
   finally:
     log.info("The sniff loop exited")
     os.kill(os.getpid(), signal.SIGINT)
开发者ID:Yasumoto,项目名称:zktraffic,代码行数:12,代码来源:sniffer.py


注:本文中的scapy.sendrecv.sniff函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。