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


Python PcapReader.close方法代码示例

本文整理汇总了Python中scapy.utils.PcapReader.close方法的典型用法代码示例。如果您正苦于以下问题:Python PcapReader.close方法的具体用法?Python PcapReader.close怎么用?Python PcapReader.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scapy.utils.PcapReader的用法示例。


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

示例1: RdpcapSource

# 需要导入模块: from scapy.utils import PcapReader [as 别名]
# 或者: from scapy.utils.PcapReader import close [as 别名]
class RdpcapSource(Source):
    """Read packets from a PCAP file send them to low exit.
     +----------+
  >>-|          |->>
     |          |
   >-|  [pcap]--|->
     +----------+
"""
    def __init__(self, fname, name=None):
        Source.__init__(self, name=name)
        self.fname = fname
        self.f = PcapReader(self.fname)
    def start(self):
        print "start"
        self.f = PcapReader(self.fname)
        self.is_exhausted = False
    def stop(self):
        print "stop"
        self.f.close()
    def fileno(self):
        return self.f.fileno()
    def deliver(self):    
        p = self.f.recv()
        print "deliver %r" % p
        if p is None:
            self.is_exhausted = True
        else:
            self._send(p)
开发者ID:guedou,项目名称:scapy-issues,代码行数:30,代码来源:scapypipes.py

示例2: sniff

# 需要导入模块: from scapy.utils import PcapReader [as 别名]
# 或者: from scapy.utils.PcapReader import close [as 别名]
def sniff(count=0, store=1, offline=None, prn = None, lfilter=None, L2socket=None, timeout=None, *arg, **karg):
    """Sniff packets
sniff([count=0,] [prn=None,] [store=1,] [offline=None,] [lfilter=None,] + L2ListenSocket args) -> list of packets
Select interface to sniff by setting conf.iface. Use show_interfaces() to see interface names.
  count: number of packets to capture. 0 means infinity
  store: wether to store sniffed packets or discard them
    prn: function to apply to each packet. If something is returned,
         it is displayed. Ex:
         ex: prn = lambda x: x.summary()
lfilter: python function applied to each packet to determine
         if further action may be done
         ex: lfilter = lambda x: x.haslayer(Padding)
offline: pcap file to read packets from, instead of sniffing them
timeout: stop sniffing after a given time (default: None)
L2socket: use the provided L2socket
    """
    c = 0

    if offline is None:
        log_runtime.info('Sniffing on %s' % conf.iface)
        if L2socket is None:
            L2socket = conf.L2listen
        s = L2socket(type=ETH_P_ALL, *arg, **karg)
    else:
        s = PcapReader(offline)

    lst = []
    if timeout is not None:
        stoptime = time.time()+timeout
    remain = None
    while 1:
        try:
            if timeout is not None:
                remain = stoptime-time.time()
                if remain <= 0:
                    break

            try:
                p = s.recv(MTU)
            except PcapTimeoutElapsed:
                continue
            if p is None:
                break
            if lfilter and not lfilter(p):
                continue
            if store:
                lst.append(p)
            c += 1
            if prn:
                r = prn(p)
                if r is not None:
                    print(r)
            if count > 0 and c >= count:
                break
        except KeyboardInterrupt:
            break
    s.close()
    return plist.PacketList(lst,"Sniffed")
开发者ID:ouje,项目名称:scapy,代码行数:60,代码来源:__init__.py

示例3: parse_pcap_files

# 需要导入模块: from scapy.utils import PcapReader [as 别名]
# 或者: from scapy.utils.PcapReader import close [as 别名]
	def parse_pcap_files(self, pcapFiles, quite=True):
		"""
		Take one more more (list, or tuple) of pcap files and parse them
		into the engine.
		"""
		if not hasattr(pcapFiles, '__iter__'):
			if isinstance(pcapFiles, str):
				pcapFiles = [pcapFiles]
			else:
				return
		for i in range(0, len(pcapFiles)):
			pcap = pcapFiles[i]
			pcapName = os.path.split(pcap)[1]
			if not quite:
				sys.stdout.write("Reading PCap File: {0}\r".format(pcapName))
				sys.stdout.flush()
			if not os.path.isfile(pcap):
				if not quite:
					sys.stdout.write("Skipping File {0}: File Not Found\n".format(pcap))
					sys.stdout.flush()
				continue
			elif not os.access(pcap, os.R_OK):
				if not quite:
					sys.stdout.write("Skipping File {0}: Permissions Issue\n".format(pcap))
					sys.stdout.flush()
				continue
			pcapr = PcapReader(pcap)  # pylint: disable=no-value-for-parameter
			packet = pcapr.read_packet()
			i = 1
			try:
				while packet:
					if not quite:
						sys.stdout.write('Parsing File: ' + pcap + ' Packets Done: ' + str(i) + '\r')
						sys.stdout.flush()
					self.parse_wireless_packet(packet)
					packet = pcapr.read_packet()
					i += 1
				i -= 1
				if not quite:
					sys.stdout.write((' ' * len('Parsing File: ' + pcap + ' Packets Done: ' + str(i))) + '\r')
					sys.stdout.write('Done With File: ' + pcap + ' Read ' + str(i) + ' Packets\n')
					sys.stdout.flush()
			except KeyboardInterrupt:
				if not quite:
					sys.stdout.write("Skipping File {0} Due To Ctl+C\n".format(pcap))
					sys.stdout.flush()
			except:  # pylint: disable=bare-except
				if not quite:
					sys.stdout.write("Skipping File {0} Due To Scapy Exception\n".format(pcap))
					sys.stdout.flush()
			self.fragment_buffer = {}
			pcapr.close()
开发者ID:jacobj10,项目名称:eapeak,代码行数:54,代码来源:parse.py

示例4: mysniff

# 需要导入模块: from scapy.utils import PcapReader [as 别名]
# 或者: from scapy.utils.PcapReader import close [as 别名]
    def mysniff(self, *arg, **karg):
        c = 0

        if self.opened_socket is not None:
            s = self.opened_socket
        else:
            if self.offline is None:
                if self.L2socket is None:
                    self.L2socket = conf.L2listen
                s = self.L2socket(type=ETH_P_ALL, *arg, **karg)
            else:
                s = PcapReader(self.offline)

        lst = []
        if self.timeout is not None:
            stoptime = time.time() + self.timeout
        remain = None
        while 1:
            if not self.running:
                break
            try:
                if self.timeout is not None:
                    remain = stoptime - time.time()
                    if remain <= 0:
                        break
                sel = select([s], [], [], remain)
                if s in sel[0]:
                    p = s.recv(MTU)
                    if p is None:
                        break
                    if self.lfilter and not self.lfilter(p):
                        continue
                    if self.store:
                        lst.append(p)
                    c += 1
                    if self.prn:
                        r = self.prn(p)
                        if r is not None:
                            print r
                    if self.stop_filter and self.stop_filter(p):
                        break
                    if 0 < self.count <= c:
                        break
            except KeyboardInterrupt:
                break
        if self.opened_socket is None:
            s.close()
        return plist.PacketList(lst, "Sniffed")
开发者ID:ShaneHarvey,项目名称:wepcracker,代码行数:50,代码来源:sniffingthread.py


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