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


Python Packet.time方法代码示例

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


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

示例1: __process_packets

# 需要导入模块: from scapy.packet import Packet [as 别名]
# 或者: from scapy.packet.Packet import time [as 别名]
    def __process_packets(self, packets, out_writer, drop_writer, validation_file):
        """
        :type packets: list[Packet]
        :return A tuple with the number of packets anonymized and the number of packets dropped
        :rtype (int, int)
        """

        for index, packet in enumerate(packets):

            if index and (index % 10000) == 0:
                self.app.log.info("pcap:{}: Process packet id = '{}'".format(self.file, index))

            packet_id = index + 1  # packet id start with 1

            # packet_backup = Packet(str(packet))
            packet_backup = packet.original
            packet_backup_time = packet.time

            try:
                try:
                    if self.app.phase is Phase.phase_1:
                        self.app.packet.discover(packet)
                    elif self.app.phase is Phase.phase_3:
                        self.app.packet.anonymize(packet)
                    elif self.app.phase is Phase.phase_4:
                        validation = self.app.packet.validate(packet)
                        if validation is not None:
                            validation_file.write("\n\nPacket id {}:\n  ".format(packet_id))
                            validation = validation.replace('\n', '\n  ')  # Indent
                            validation_file.write(validation)

                except Exception as e:
                    if isinstance(e, ExplicitDropException):
                        self.app.log.debug("file:pcap:{}: Packet explicitly dropped: id = '{}', {}, {}".format(
                            self.file, packet_id, e.message, repr(packet.summary())))
                    elif isinstance(e, ImplicitDropException):
                        self.app.log.warning("file:pcap:{}: Packet implicitly dropped: id = '{}', {}, {}".format(
                            self.file, packet_id, e.message, repr(packet.summary())))
                    elif isinstance(e, ErrorDropException):
                        self.app.log.error("file:pcap:{}: Error packet dropped: id = '{}', {}, {}".format(
                            self.file, packet_id, e.message, repr(packet.summary())))
                    else:
                        self.app.log.critical("file:pcap:{}: Unexpected error packet dropped: id = '{}', {}, {}".format(
                            self.file, packet_id, e.message, repr(packet.summary())))

                    if self.app.phase is Phase.phase_3:
                        packet_backup = Packet(packet_backup)
                        packet_backup.time = packet_backup_time
                        drop_writer.write(packet_backup)

                else:
                    if self.app.phase is Phase.phase_3:
                        out_writer.write(packet)

            except Exception as e:
                self.app.log.critical(
                    "sirano:file:pcap:{}: Unexpected error: id = '{}', exception = '{}', message = '{}', {}".format(
                        self.file, packet_id, type(e), e.message, repr(packet.summary())))
开发者ID:dynamicdeploy,项目名称:sirano,代码行数:60,代码来源:pcap.py


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