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

Python packet.Packet类代码示例

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

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



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

示例1: add_payload

 def add_payload(self, payload):
     if self.underlayer and isinstance(self.underlayer, TCP):
         if isinstance(payload, (SOCKS5Request, SOCKS4Request)):
             self.underlayer.dport = 1080
         elif isinstance(payload, (SOCKS5Reply, SOCKS4Reply)):
             self.underlayer.sport = 1080
     Packet.add_payload(self, payload)
开发者ID:commial,项目名称:scapy,代码行数:7,代码来源:socks.py


示例2: __init__

 def __init__(self, *args, **fields):
     try:
         self.tls_ctx = fields["ctx"]
         del(fields["ctx"])
     except KeyError:
         self.tls_ctx = None
     Packet.__init__(self, *args, **fields)
开发者ID:ALSchwalm,项目名称:scapy-ssl_tls,代码行数:7,代码来源:ssl_tls.py


示例3: __process_packets

    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,代码行数:58,代码来源:pcap.py


示例4: __init__

 def __init__(self, *args, **fields):
     try:
         self.tls_ctx = fields["ctx"]
         del(fields["ctx"])
         self.above_tls10 = self.tls_ctx.params.negotiated.version > TLSVersion.TLS_1_0
         if self.explicit_iv_field not in self.fields_desc and self.above_tls10:
             self.fields_desc.append(self.explicit_iv_field)
         for field in self.decryptable_fields:
             if field not in self.fields_desc:
                 self.fields_desc.append(field)
     except KeyError:
         self.tls_ctx = None
     Packet.__init__(self, *args, **fields)
开发者ID:Phantom522,项目名称:scapy-ssl_tls,代码行数:13,代码来源:ssl_tls.py


示例5: guess_payload_class

    def guess_payload_class(self, payload):

        try:
            dlpdu_type = payload[0]
            return EtherCat.ETHERCAT_TYPE12_DLPDU_TYPES[dlpdu_type]

        except KeyError:
            log_runtime.error(
                '{}.guess_payload_class() - unknown or invalid '
                'DLPDU type'.format(self.__class__.__name__))
            return Packet.guess_payload_class(self, payload)

        return Packet.guess_payload_class(self, payload)
开发者ID:plorinquer,项目名称:scapy,代码行数:13,代码来源:ethercat.py


示例6: do_build

    def do_build(self):
        if not isinstance(self.payload, IPv6):
            return Packet.do_build(self)
        ipv6 = self.payload

        self._reserved = 0x03

        # NEW COMPRESSION TECHNIQUE!
        # a ) Compression Techniques

        # 1. Set Traffic Class
        if self.tf == 0x0:
            self.tc_ecn = ipv6.tc >> 6
            self.tc_dscp = ipv6.tc & 0x3F
            self.flowlabel = ipv6.fl
        elif self.tf == 0x1:
            self.tc_ecn = ipv6.tc >> 6
            self.flowlabel = ipv6.fl
        elif self.tf == 0x2:
            self.tc_ecn = ipv6.tc >> 6
            self.tc_dscp = ipv6.tc & 0x3F
        else:  # self.tf == 0x3:
            pass  # no field is set

        # 2. Next Header
        if self.nh == 0x0:
            self.nh = 0  # ipv6.nh
        elif self.nh == 0x1:
            self.nh = 0  # disable compression
            # The Next Header field is compressed and the next header is encoded using LOWPAN_NHC, which is discussed in Section 4.1.  # noqa: E501
            warning('Next header compression is not implemented yet ! Will be ignored')  # noqa: E501

        # 3. HLim
        if self.hlim == 0x0:
            self._hopLimit = ipv6.hlim
        else:  # if hlim is 1, 2 or 3, there are nothing to do!
            pass

        # 4. Context (which context to use...)
        if self.cid == 0x0:
            pass
        else:
            # TODO: Context Unimplemented yet in my class
            self._contextIdentifierExtension = 0

        # 5. Compress Source Addr
        self.compressSourceAddr(ipv6)
        self.compressDestinyAddr(ipv6)

        return Packet.do_build(self)
开发者ID:segment-routing,项目名称:scapy,代码行数:50,代码来源:sixlowpan.py


示例7: post_build

    def post_build(self, p, pay):
        # patch the update of block_length, as requests field must not be
        # included. block_length is always 60
        if self.block_length is None:
            p = p[:2] + struct.pack("!H", 60) + p[4:]

        return Packet.post_build(self, p, pay)
开发者ID:commial,项目名称:scapy,代码行数:7,代码来源:pnio_rpc.py


示例8: guess_payload_class

 def guess_payload_class(self, payload):
     if self.type == 0x02 and (0x08 <= self.subtype <= 0xF and self.subtype != 0xD):  # noqa: E501
         return Dot11QoS
     elif self.FCfield & 0x40:
         return Dot11WEP
     else:
         return Packet.guess_payload_class(self, payload)
开发者ID:netkey,项目名称:scapy,代码行数:7,代码来源:dot11.py


示例9: guess_payload_class

 def guess_payload_class(self, payload):
     if self.frame_control & 0x02: # we have a security header
         return ZigbeeSecurityHeader
     elif self.aps_frametype == 0: # data
         return ZigbeeClusterLibrary # TODO might also be another frame
     elif self.aps_frametype == 1: # command
         return ZigbeeAppCommandPayload
     else:
         return Packet.guess_payload_class(self, payload)
开发者ID:BastilleResearch,项目名称:scapy-radio,代码行数:9,代码来源:zigbee.py


示例10: guess_payload_class

 def guess_payload_class(self, payload):
     if self.flags & 0x02:
         return ZigbeeSecurityHeader
     elif self.frametype == 0:
         return ZigbeeAppDataPayload
     elif self.frametype == 1:
         return ZigbeeNWKCommandPayload
     else:
         return Packet.guess_payload_class(self, payload)
开发者ID:lopessec,项目名称:SecBee,代码行数:9,代码来源:zigbee.py


示例11: build

 def build(self):
     # update fields that depend on values in SCSI layer
     if SCSICmd in self:
         scsicmd = self[SCSICmd].payload
         if scsicmd.default_fields.has_key("AllocationLength"):
             self.overloaded_fields.update({"ExpectedDataSize": scsicmd.AllocationLength})
         if scsicmd.default_fields.has_key("TransferLength"):
             self.overloaded_fields.update({"ExpectedDataSize": scsicmd.TransferLength * self.BLOCK_SIZE})
     return Packet.build(self)
开发者ID:0xroot,项目名称:usb-device-fuzzing,代码行数:9,代码来源:MSC.py


示例12: guess_payload_class

    def guess_payload_class(self, payload):
        if len(payload) < self._min_ieo_len:
            return Packet.guess_payload_class(self, payload)

        # Look at fields of the generic ICMPExtensionObject to determine which
        # bound extension type to use.
        ieo = ICMPExtensionObject(payload)
        if ieo.len < self._min_ieo_len:
            return Packet.guess_payload_class(self, payload)

        for fval, cls in self.payload_guess:
            ok = 1
            for k, v in fval.iteritems():
                if not hasattr(ieo, k) or v != ieo.getfieldval(k):
                    ok = 0
                    break
            if ok:
                return cls
        return ICMPExtensionObject
开发者ID:Osso,项目名称:scapy,代码行数:19,代码来源:icmp_extensions.py


示例13: getlayer

 def getlayer(self, cls, nb=1, _track=None):
     layer = None
     if cls == EAP:
         for eap_class in EAP.registered_methods.values():
             if isinstance(self, eap_class):
                 layer = self
                 break
     else:
         layer = Packet.getlayer(self, cls, nb, _track)
     return layer
开发者ID:mcpat,项目名称:scapy,代码行数:10,代码来源:eap.py


示例14: getlayer

 def getlayer(self, cls, nb=1, _track=None):
     layer = None
     if cls == RadiusAttribute:
         for attr_class in RadiusAttribute.registered_attributes.values():
             if isinstance(self, attr_class):
                 layer = self
                 break
     else:
         layer = Packet.getlayer(self, cls, nb, _track)
     return layer
开发者ID:thibaultdelmas,项目名称:scapy,代码行数:10,代码来源:radius.py


示例15: pre_dissect

 def pre_dissect(self, s):
     if self.firstlayer().name == TLSRecord.name:
         # Go get the underlaying records context
         # Will allow us to differentiate Ephemeral RSA (Freak)
         # From DHE (Logjam) and ECDHE
         try:
             self.tls_ctx = self.firstlayer().tls_ctx
         except AttributeError:
             self.tls_ctx = None
     return Packet.pre_dissect(self, s)
开发者ID:ALSchwalm,项目名称:scapy-ssl_tls,代码行数:10,代码来源:ssl_tls.py


示例16: guess_payload_class

    def guess_payload_class(self, payload):

        start_line = payload.splitlines(True)[0]

        if self.re_request_line.match(start_line) is not None:
            return SIPRequest
        elif self.re_status_line.match(start_line) is not None:
            return SIPResponse

        return Packet.guess_payload_class(self, payload)
开发者ID:dynamicdeploy,项目名称:sirano,代码行数:10,代码来源:sip.py


示例17: __init__

    def __init__(self, _pkt="", post_transform=None, _internal=0,
                 _underlayer=None, tls_session=None, **fields):
        try:
            setme = self.tls_session is None
        except:
            setme = True

        if setme:
            if tls_session is None:
                self.tls_session = tlsSession()
            else:
                self.tls_session = tls_session

        self.rcs_snap_init = self.tls_session.rcs.snapshot()
        self.wcs_snap_init = self.tls_session.wcs.snapshot()

        Packet.__init__(self, _pkt=_pkt, post_transform=post_transform,
                        _internal=_internal, _underlayer=_underlayer,
                        **fields)
开发者ID:mcpat,项目名称:scapy,代码行数:19,代码来源:session.py


示例18: guess_payload_class

 def guess_payload_class(self, payload):
     if self.fcf_frametype == 0x00:
         return Dot15d4Beacon
     elif self.fcf_frametype == 0x01:
         return Dot15d4Data
     elif self.fcf_frametype == 0x02:
         return Dot15d4Ack
     elif self.fcf_frametype == 0x03:
         return Dot15d4Cmd
     else:
         return Packet.guess_payload_class(self, payload)
开发者ID:commial,项目名称:scapy,代码行数:11,代码来源:dot15d4.py


示例19: guess_payload_class

 def guess_payload_class(self, payload):
     # Profile-wide commands
     if self.zcl_frametype == 0x00 and self.command_identifier == 0x00:
         return ZCLGeneralReadAttributes
     elif self.zcl_frametype == 0x00 and self.command_identifier == 0x01:
         return ZCLGeneralReadAttributesResponse
     # Cluster-specific commands
     elif self.zcl_frametype == 0x01 and self.command_identifier == 0x00 and self.direction == 0 and self.underlayer.cluster == 0x0700:  # "price"  # noqa: E501
         return ZCLPriceGetCurrentPrice
     elif self.zcl_frametype == 0x01 and self.command_identifier == 0x01 and self.direction == 0 and self.underlayer.cluster == 0x0700:  # "price"  # noqa: E501
         return ZCLPriceGetScheduledPrices
     elif self.zcl_frametype == 0x01 and self.command_identifier == 0x00 and self.direction == 1 and self.underlayer.cluster == 0x0700:  # "price"  # noqa: E501
         return ZCLPricePublishPrice
     else:
         return Packet.guess_payload_class(self, payload)
开发者ID:commial,项目名称:scapy,代码行数:15,代码来源:zigbee.py


示例20: guess_payload_class

 def guess_payload_class(self, payload):
     """ Decides if the payload is an HTTP Request or Response, or
         something else """
     try:
         prog = re.compile(r"^(?:OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT) " r"(?:.+?) " r"HTTP/\d\.\d$")
         req = payload[: payload.index("\r\n")]
         result = prog.match(req)
         if result:
             return HTTPRequest
         else:
             prog = re.compile(r"^HTTP/\d\.\d \d\d\d .*$")
             result = prog.match(req)
             if result:
                 return HTTPResponse
     except:
         pass
     return Packet.guess_payload_class(self, payload)
开发者ID:jphgxq,项目名称:scapy-http,代码行数:17,代码来源:http.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python sendrecv.sniff函数代码示例发布时间:2022-05-27
下一篇:
Python packet.bind_layers函数代码示例发布时间: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