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


Python plist.SndRcvList方法代码示例

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


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

示例1: write

# 需要导入模块: from scapy import plist [as 别名]
# 或者: from scapy.plist import SndRcvList [as 别名]
def write(self, pkt):
        """
        Writes a Packet, a SndRcvList object, or bytes to a pcap file.

        :param pkt: Packet(s) to write (one record for each Packet), or raw
                    bytes to write (as one record).
        :type pkt: iterable[scapy.packet.Packet], scapy.packet.Packet or bytes
        """
        if isinstance(pkt, bytes):
            if not self.header_present:
                self._write_header(pkt)
            self._write_packet(pkt)
        else:
            # Import here to avoid a circular dependency
            from scapy.plist import SndRcvList
            if isinstance(pkt, SndRcvList):
                pkt = (p for t in pkt for p in t)
            else:
                pkt = pkt.__iter__()
            for p in pkt:

                if not self.header_present:
                    self._write_header(p)

                if self.linktype != conf.l2types.get(type(p), None):
                    warning("Inconsistent linktypes detected!"
                            " The resulting PCAP file might contain"
                            " invalid packets."
                            )

                self._write_packet(p) 
开发者ID:secdev,项目名称:scapy,代码行数:33,代码来源:utils.py

示例2: __sr_loop

# 需要导入模块: from scapy import plist [as 别名]
# 或者: from scapy.plist import SndRcvList [as 别名]
def __sr_loop(srfunc, pkts, prn=lambda x: x[1].summary(),
              prnfail=lambda x: x.summary(),
              inter=1, timeout=None, count=None, verbose=None, store=1,
              *args, **kargs):
    n = 0
    r = 0
    ct = conf.color_theme
    if verbose is None:
        verbose = conf.verb
    parity = 0
    ans = []
    unans = []
    if timeout is None:
        timeout = min(2 * inter, 5)
    try:
        while True:
            parity ^= 1
            col = [ct.even, ct.odd][parity]
            if count is not None:
                if count == 0:
                    break
                count -= 1
            start = time.time()
            if verbose > 1:
                print("\rsend...\r", end=' ')
            res = srfunc(pkts, timeout=timeout, verbose=0, chainCC=True, *args, **kargs)  # noqa: E501
            n += len(res[0]) + len(res[1])
            r += len(res[0])
            if verbose > 1 and prn and len(res[0]) > 0:
                msg = "RECV %i:" % len(res[0])
                print("\r" + ct.success(msg), end=' ')
                for p in res[0]:
                    print(col(prn(p)))
                    print(" " * len(msg), end=' ')
            if verbose > 1 and prnfail and len(res[1]) > 0:
                msg = "fail %i:" % len(res[1])
                print("\r" + ct.fail(msg), end=' ')
                for p in res[1]:
                    print(col(prnfail(p)))
                    print(" " * len(msg), end=' ')
            if verbose > 1 and not (prn or prnfail):
                print("recv:%i  fail:%i" % tuple(map(len, res[:2])))
            if store:
                ans += res[0]
                unans += res[1]
            end = time.time()
            if end - start < inter:
                time.sleep(inter + start - end)
    except KeyboardInterrupt:
        pass

    if verbose and n > 0:
        print(ct.normal("\nSent %i packets, received %i packets. %3.1f%% hits." % (n, r, 100.0 * r / n)))  # noqa: E501
    return SndRcvList(ans), PacketList(unans) 
开发者ID:secdev,项目名称:scapy,代码行数:56,代码来源:sendrecv.py


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