• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sendrecv.sniff函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: run

 def run(self):
     while self.kill_received is not True:
         try:
             sniff(
                 filter=self.FILTER,
                 prn=self._dispatch_to_handler,
                 store=0,
                 timeout=5,
                 iface=str(self._interface.name),
             )
         except:
             self._logger.exception("Unexpected error occurred in listener thread")
开发者ID:NeoXiD,项目名称:DHCprefix6,代码行数:12,代码来源:network.py


示例17: run

  def run(self, *args, **kwargs):
    try:
      sniff_kwargs = {"filter": self._pfilter, "store": 0, "prn": self.handle_packet}

      if "offline" in kwargs:
        sniff_kwargs["offline"] = kwargs["offline"]

      sniff(**sniff_kwargs)
    except socket.error as ex:
      sys.stderr.write("Error: %s, filter: %s\n" % (ex, self._pfilter))
    finally:
      if "offline" not in kwargs:
        os.kill(os.getpid(), signal.SIGINT)
开发者ID:AkihiroSuda,项目名称:zktraffic,代码行数:13,代码来源:omni_sniffer.py


示例18: connect

	def connect(self, essid, rsnInfo = ''):
		"""
		Connect/Associate with an access point.
		errDict = {
			-1:"Already Connected",
			0:"No Error",
			1:"Failed To Get Probe Response",
			2:"Failed To Get Authentication Response",
			3:"Failed To Get Association Response",
			4:"Authentication Request Received Fail Response",
			5:"Association Request Received Fail Response"
		}
		"""
		# Dot11 Probe Request (to get authentication information if applicable)
		if rsnInfo == None:	# None explicitly means go get it, leave it '' to proceed with out it
			rsnInfo = self.getRSNInformation(essid)
		
		# Dot11 Authentication Request
		sendp(	RadioTap()/
				Dot11(addr1=self.dest_mac, addr2=self.source_mac, addr3=self.bssid, SC=self.__unfuckupSC__())/
				Dot11Auth(seqnum=1),
				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('Dot11Auth'):
			return 2
		if self.lastpacket.getlayer('Dot11Auth').status != 0:
			return 4
		
		# Dot11 Association Request
		sendp(	RadioTap()/
				Dot11(addr1=self.bssid, addr2=self.source_mac, addr3=self.bssid, SC=self.__unfuckupSC__(), subtype=0)/
				Dot11AssoReq(cap='ESS+short-preamble+short-slot', listen_interval=10)/
				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')/
				rsnInfo,
				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(Dot11AssoResp):
			return 3
		
		if self.lastpacket.getlayer(Dot11AssoResp).status != 0:
			return 5
		
		self.connected = True
		self.sequence = 0	# reset it
		return 0
开发者ID:FomkaV,项目名称:wifi-arsenal,代码行数:50,代码来源:inject.py


示例19: voip_play

def voip_play(s1,list=None,**kargs):
    FIFO=get_temp_file()
    FIFO1=FIFO % 1
    FIFO2=FIFO % 2
    
    os.mkfifo(FIFO1)
    os.mkfifo(FIFO2)
    try:
        os.system("soxmix -t .ul %s -t .ul %s -t ossdsp /dev/dsp &" % (FIFO1,FIFO2))
        
        c1=open(FIFO1,"w", 4096)
        c2=open(FIFO2,"w", 4096)
        fcntl.fcntl(c1.fileno(),fcntl.F_SETFL, os.O_NONBLOCK)
        fcntl.fcntl(c2.fileno(),fcntl.F_SETFL, os.O_NONBLOCK)
    
    #    dsp,rd = os.popen2("sox -t .ul -c 2 - -t ossdsp /dev/dsp")
        def play(pkt, last=None):
            if last is None:
                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))
    
        if list is None:
            sniff(store=0, prn=play, **kargs)
        else:
            for p in list:
                play(p)
    finally:
        os.unlink(FIFO1)
        os.unlink(FIFO2)
开发者ID:guedou,项目名称:scapy-issues,代码行数:48,代码来源:voip.py


示例20: voip_play

def voip_play(s1, lst=None, **kargs):
    """Play VoIP packets with RAW data that
    are either sniffed either from an IP, or
    specified as a list.

    It will play only the incoming packets !

    :param s1: The IP of the src of all VoIP packets.
    :param lst: (optional) A list of packets to load
    :type s1: string
    :type lst: list

    :Example:

    >>> voip_play("64.2.142.189")
    while calling '[email protected]'

    >>> voip_play("64.2.142.189", lst)
    with list a list of packets with VoIP data
    in their RAW layer

    .. seealso:: voip_play2
    to play both the outcoming and incoming packets
    at the same time.

    .. seealso:: voip_play3
    to read RTP VoIP packets
    """

    dsp, rd = os.popen2(sox_base % "")

    def play(pkt):
        if not pkt:
            return
        if not pkt.haslayer(UDP) or not pkt.haslayer(IP):
            return
        ip = pkt.getlayer(IP)
        if s1 == ip.src:
            dsp.write(pkt.getlayer(conf.raw_layer).load[12:])
    try:
        if lst is None:
            sniff(store=0, prn=play, **kargs)
        else:
            for p in lst:
                play(p)
    finally:
        dsp.close()
        rd.close()
开发者ID:plorinquer,项目名称:scapy,代码行数:48,代码来源:voip.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sendrecv.srp1函数代码示例发布时间:2022-05-27
下一篇:
Python packet.Packet类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap