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


Python conf.raw_layer函数代码示例

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


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

示例1: _PPIGuessPayloadClass

def _PPIGuessPayloadClass(p, **kargs):
    """ This function tells the PacketListField how it should extract the
        TLVs from the payload.  We pass cls only the length string
        pfh_len says it needs.  If a payload is returned, that means
        part of the string was unused.  This converts to a Raw layer, and
        the remainder of p is added as Raw's payload.  If there is no
        payload, the remainder of p is added as out's payload.
    """
    if len(p) >= 4:
        t, pfh_len = struct.unpack("<HH", p[:4])
        # Find out if the value t is in the dict _ppi_types.
        # If not, return the default TLV class
        cls = getPPIType(t, "default")
        pfh_len += 4
        out = cls(p[:pfh_len], **kargs)
        if (out.payload):
            out.payload = conf.raw_layer(out.payload.load)
            out.payload.underlayer = out
            if (len(p) > pfh_len):
                out.payload.payload = conf.padding_layer(p[pfh_len:])
                out.payload.payload.underlayer = out.payload
        elif (len(p) > pfh_len):
            out.payload = conf.padding_layer(p[pfh_len:])
            out.payload.underlayer = out
    else:
        out = conf.raw_layer(p, **kargs)
    return out
开发者ID:segment-routing,项目名称:scapy,代码行数:27,代码来源:ppi.py

示例2: getfield

 def getfield(self, pkt, s):
     c = l = None
     if self.length_from is not None:
         l = self.length_from(pkt)
     elif self.count_from is not None:
         c = self.count_from(pkt)
         
     lst = []
     ret = ""
     remain = s
     if l is not None:
         remain,ret = s[:l],s[l:]
     while remain:
         if c is not None:
             if c <= 0:
                 break
             c -= 1
         try:
             p = self.m2i(pkt,remain)
         except Exception:
             if conf.debug_dissector:
                 raise
             p = conf.raw_layer(load=remain)
             remain = ""
         else:
             if conf.padding_layer in p:
                 pad = p[conf.padding_layer]
                 remain = pad.load
                 del(pad.underlayer.payload)
             else:
                 remain = ""
         lst.append(p)
     return remain+ret,lst
开发者ID:smainand,项目名称:scapy,代码行数:33,代码来源:fields.py

示例3: recv

    def recv(self, x=MTU):
        pkt, sa_ll = self.ins.recvfrom(x)
        if sa_ll[2] == socket.PACKET_OUTGOING:
            return None
        if sa_ll[3] in conf.l2types:
            cls = conf.l2types[sa_ll[3]]
            lvl = 2
        elif sa_ll[1] in conf.l3types:
            cls = conf.l3types[sa_ll[1]]
            lvl = 3
        else:
            cls = conf.default_l2
            warning(" Impossivel saber o tipo (interface=%s protocol=%#x familia=%i). Usando %s" % (sa_ll[0],sa_ll[1],sa_ll[3],cls.name))
            lvl = 2

        try:
            pkt = cls(pkt)
        except KeyboardInterrupt:
            raise
        except:
            if conf.debug_dissector:
                raise
            pkt = conf.raw_layer(pkt)
        if lvl == 2:
            pkt = pkt.payload
            
        if pkt is not None:
            pkt.time = get_last_packet_timestamp(self.ins)
        return pkt
开发者ID:Marcus1911,项目名称:mptcp-scapy,代码行数:29,代码来源:linux.py

示例4: recv

    def recv(self, x=MTU):
        pkt, sa_ll = self.ins.recvfrom(x)
        if sa_ll[2] == socket.PACKET_OUTGOING:
            return None
        if sa_ll[3] in conf.l2types:
            cls = conf.l2types[sa_ll[3]]
            lvl = 2
        elif sa_ll[1] in conf.l3types:
            cls = conf.l3types[sa_ll[1]]
            lvl = 3
        else:
            cls = conf.default_l2
            warning("Unable to guess type (interface=%s protocol=%#x family=%i). Using %s", sa_ll[0], sa_ll[1], sa_ll[3], cls.name)  # noqa: E501
            lvl = 3

        try:
            pkt = cls(pkt)
        except KeyboardInterrupt:
            raise
        except Exception:
            if conf.debug_dissector:
                raise
            pkt = conf.raw_layer(pkt)
        if lvl == 2:
            pkt = pkt.payload

        if pkt is not None:
            from scapy.arch import get_last_packet_timestamp
            pkt.time = get_last_packet_timestamp(self.ins)
        return pkt
开发者ID:commial,项目名称:scapy,代码行数:30,代码来源:supersocket.py

示例5: recv

        def recv(self, x=MTU):
            ll = self.ins.datalink()
            if ll in conf.l2types:
                cls = conf.l2types[ll]
            else:
                cls = conf.default_l2
                warning(
                    "Unable to guess datalink type (interface=%s linktype=%i). Using %s" % (self.iface, ll, cls.name)
                )

            pkt = self.ins.next()
            if pkt is not None:
                ts, pkt = pkt
            if pkt is None:
                return

            try:
                pkt = cls(pkt)
            except KeyboardInterrupt:
                raise
            except:
                if conf.debug_dissector:
                    raise
                pkt = conf.raw_layer(pkt)
            pkt.time = ts
            return pkt
开发者ID:insomniacslk,项目名称:scapy,代码行数:26,代码来源:pcapdnet.py

示例6: m2i

 def m2i(self, pkt, m):
     ret = None
     eap_packet_len = struct.unpack("!H", m[2:4])[0]
     if eap_packet_len < 254:
         # If the EAP packet has not been fragmented, build a Scapy EAP
         # packet from the data.
         ret = EAP(m)
     else:
         ret = conf.raw_layer(m)
     return ret
开发者ID:thibaultdelmas,项目名称:scapy,代码行数:10,代码来源:radius.py

示例7: do_dissect_payload

 def do_dissect_payload(self, s):
     if s:
         try:
             p = SSLv2(s, _internal=1, _underlayer=self,
                       tls_session = self.tls_session)
         except KeyboardInterrupt:
             raise
         except:
             p = conf.raw_layer(s, _internal=1, _underlayer=self)
         self.add_payload(p)
开发者ID:6WIND,项目名称:scapy,代码行数:10,代码来源:record_sslv2.py

示例8: __div__

 def __div__(self, other):
     if isinstance(other, Packet):
         cloneA = self.copy()
         cloneB = other.copy()
         cloneA.add_payload(cloneB)
         return cloneA
     elif type(other) is str:
         return self/conf.raw_layer(load=other)
     else:
         return other.__rdiv__(self)
开发者ID:danieljakots,项目名称:scapy,代码行数:10,代码来源:packet.py

示例9: recv

 def recv(self, x=MTU):
     pkt, sa_ll = self.ins.recvfrom(x)
     if sa_ll[2] == socket.PACKET_OUTGOING:
         return None
     try:
         q = self.LL(pkt)
     except KeyboardInterrupt:
         raise
     except:
         if conf.debug_dissector:
             raise
         q = conf.raw_layer(pkt)
     q.time = get_last_packet_timestamp(self.ins)
     return q
开发者ID:thibaultdelmas,项目名称:scapy,代码行数:14,代码来源:linux.py

示例10: read_packet

 def read_packet(self, size=MTU):
     rp = RawPcapNgReader.read_packet(self, size=size)
     if rp is None:
         return None
     s, (linktype, sec, usec, wirelen) = rp
     try:
         p = conf.l2types[linktype](s)
     except KeyboardInterrupt:
         raise
     except:
         if conf.debug_dissector:
             raise
         p = conf.raw_layer(s)
     p.time = sec+0.000001*usec
     return p
开发者ID:danieljakots,项目名称:scapy,代码行数:15,代码来源:utils.py

示例11: do_dissect_payload

 def do_dissect_payload(self, s):
     """
     Try to dissect the following data as a TLS message.
     Note that overloading .guess_payload_class() would not be enough,
     as the TLS session to be used would get lost.
     """
     if s:
         try:
             p = TLS(s, _internal=1, _underlayer=self,
                     tls_session = self.tls_session)
         except KeyboardInterrupt:
             raise
         except:
             p = conf.raw_layer(s, _internal=1, _underlayer=self)
         self.add_payload(p)
开发者ID:martingalloar,项目名称:scapy,代码行数:15,代码来源:record_tls13.py

示例12: read_packet

 def read_packet(self, size=MTU):
     rp = RawPcapReader.read_packet(self, size=size)
     if rp is None:
         return None
     s,(sec,usec,wirelen) = rp
     
     try:
         p = self.LLcls(s)
     except KeyboardInterrupt:
         raise
     except:
         if conf.debug_dissector:
             raise
         p = conf.raw_layer(s)
     p.time = sec + (0.000000001 if self.nano else 0.000001) * usec
     return p
开发者ID:mcpat,项目名称:scapy,代码行数:16,代码来源:utils.py

示例13: do_dissect_payload

 def do_dissect_payload(self, s):
     if s:
         cls = self.guess_payload_class(s)
         try:
             p = cls(s, _internal=1, _underlayer=self)
         except KeyboardInterrupt:
             raise
         except:
             if conf.debug_dissector:
                 if isinstance(cls,type) and issubclass(cls,Packet):
                     log_runtime.error("%s dissector failed" % cls.name)
                 else:
                     log_runtime.error("%s.guess_payload_class() returned [%s]" % (self.__class__.__name__,repr(cls)))
                 if cls is not None:
                     raise
             p = conf.raw_layer(s, _internal=1, _underlayer=self)
         self.add_payload(p)
开发者ID:danieljakots,项目名称:scapy,代码行数:17,代码来源:packet.py

示例14: add_payload

 def add_payload(self, payload):
     if payload is None:
         return
     elif not isinstance(self.payload, NoPayload):
         self.payload.add_payload(payload)
     else:
         if isinstance(payload, Packet):
             self.payload = payload
             payload.add_underlayer(self)
             for t in self.aliastypes:
                 if payload.overload_fields.has_key(t):
                     self.overloaded_fields = payload.overload_fields[t]
                     break
         elif type(payload) is str:
             self.payload = conf.raw_layer(load=payload)
         else:
             raise TypeError("payload must be either 'Packet' or 'str', not [%s]" % repr(payload))
开发者ID:danieljakots,项目名称:scapy,代码行数:17,代码来源:packet.py

示例15: __gen_send

def __gen_send(s, x, inter=0, loop=0, count=None, verbose=None, realtime=None, return_packets=False, *args, **kargs):
    if isinstance(x, str):
        x = conf.raw_layer(load=x)
    if not isinstance(x, Gen):
        x = SetGen(x)
    if verbose is None:
        verbose = conf.verb
    n = 0
    if count is not None:
        loop = -count
    elif not loop:
        loop = -1
    if return_packets:
        sent_packets = plist.PacketList()
    try:
        while loop:
            dt0 = None
            for p in x:
                if realtime:
                    ct = time.time()
                    if dt0:
                        st = dt0+p.time-ct
                        if st > 0:
                            time.sleep(st)
                    else:
                        dt0 = ct-p.time
                s.send(p)
                if return_packets:
                    sent_packets.append(p)
                n += 1
                if verbose:
                    os.write(1,".")
                time.sleep(inter)
            if loop < 0:
                loop += 1
    except KeyboardInterrupt:
        pass
    s.close()
    if verbose:
        print("\nSent %i packets." % n)
    if return_packets:
        return sent_packets
开发者ID:mcpat,项目名称:scapy,代码行数:42,代码来源:sendrecv.py


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