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

Python compat.chb函数代码示例

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

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



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

示例1: in6_getRandomizedIfaceId

def in6_getRandomizedIfaceId(ifaceid, previous=None):
    """
    Implements the interface ID generation algorithm described in RFC 3041.
    The function takes the Modified EUI-64 interface identifier generated
    as described in RFC 4291 and an optional previous history value (the
    first element of the output of this function). If no previous interface
    identifier is provided, a random one is generated. The function returns
    a tuple containing the randomized interface identifier and the history
    value (for possible future use). Input and output values are provided in
    a "printable" format as depicted below.

    ex:
    >>> in6_getRandomizedIfaceId('20b:93ff:feeb:2d3')
    ('4c61:76ff:f46a:a5f3', 'd006:d540:db11:b092')
    >>> in6_getRandomizedIfaceId('20b:93ff:feeb:2d3',
                                 previous='d006:d540:db11:b092')
    ('fe97:46fe:9871:bd38', 'eeed:d79c:2e3f:62e')
    """

    s = b""
    if previous is None:
        d = b"".join(chb(x) for x in range(256))
        for _ in range(8):
            s += chb(random.choice(d))
        previous = s
    s = inet_pton(socket.AF_INET6, "::" + ifaceid)[8:] + previous
    import hashlib
    s = hashlib.md5(s).digest()
    s1, s2 = s[:8], s[8:]
    s1 = chb(orb(s1[0]) | 0x04) + s1[1:]
    s1 = inet_ntop(socket.AF_INET6, b"\xff" * 8 + s1)[20:]
    s2 = inet_ntop(socket.AF_INET6, b"\xff" * 8 + s2)[20:]
    return (s1, s2)
开发者ID:commial,项目名称:scapy,代码行数:33,代码来源:utils6.py


示例2: post_build

 def post_build(self, p, pay):
     if self.length is None:
         tmp_len = len(p)
         tmp_pay = p[:2] + chb((tmp_len >> 8) & 0xff)
         p = tmp_pay + chb(tmp_len & 0xff) + p[4:]
     p += pay
     return p
开发者ID:netkey,项目名称:scapy,代码行数:7,代码来源:isakmp.py


示例3: post_build

    def post_build(self, p, pay):
        p += pay

        if self.keysize is None:
            keysize = len(self.authdata)
            p = p[:6] + chb((keysize >> 8) & 0xff) + chb(keysize & 0xff) + p[8:]  # noqa: E501

        return p
开发者ID:commial,项目名称:scapy,代码行数:8,代码来源:eigrp.py


示例4: post_build

 def post_build(self, pkt, pay):
     if self.len is None:
         # len should be a FieldLenField but has an unsupported
         # format (14 bits)
         flags = orb(pkt[0]) & 0xc0
         length = len(self.value)
         pkt = chb(flags + (length >> 8)) + chb(length % 256) + pkt[2:]
     return pkt + pay
开发者ID:commial,项目名称:scapy,代码行数:8,代码来源:lltd.py


示例5: post_build

    def post_build(self, p, pay):
        p += pay

        if self.len is None:
            l = len(p)
            p = p[:2] + chb((l >> 8) & 0xff) + chb(l & 0xff) + p[4:]

        return p
开发者ID:plorinquer,项目名称:scapy,代码行数:8,代码来源:eigrp.py


示例6: post_build

 def post_build(self, p, pay):
     p += pay
     if self.Length is None:
         l = len(p)
         p = p[:6] + chb((l >> 8) & 0xff) + chb(l & 0xff) + p[8:]
     if self.chksum is None:
         ck = checksum(p)
         p = p[:2] + chb(ck >> 8) + chb(ck & 0xff) + p[4:]
     return p
开发者ID:plorinquer,项目名称:scapy,代码行数:9,代码来源:rsvp.py


示例7: decompressDestinyAddr

    def decompressDestinyAddr(self, packet):
        try:
            tmp_ip = inet_pton(socket.AF_INET6, self.destinyAddr)
        except socket.error:
            tmp_ip = b"\x00" * 16

        if self.m == 0 and self.dac == 0:
            if self.dam == 0:
                pass
            elif self.dam == 1:
                tmp_ip = LINK_LOCAL_PREFIX[0:8] + tmp_ip[-8:]
            elif self.dam == 2:
                tmp_ip = LINK_LOCAL_PREFIX[0:8] + b"\x00\x00\x00\xff\xfe\x00" + tmp_ip[-2:]  # noqa: E501
            """else: #self.dam == 3
                raise Exception('Unimplemented')"""

        elif self.m == 0 and self.dac == 1:
            if self.dam == 0:
                raise Exception('Reserved')
            elif self.dam == 0x3:
                underlayer = self.underlayer
                while underlayer is not None and not isinstance(underlayer, Dot15d4Data):  # noqa: E501
                    underlayer = underlayer.underlayer
                if type(underlayer) == Dot15d4Data:
                    if underlayer.underlayer.fcf_destaddrmode == 3:
                        tmp_ip = LINK_LOCAL_PREFIX[0:8] + struct.pack(">Q", underlayer.dest_addr)  # noqa: E501
                        # Turn off the bit 7.
                        tmp_ip = tmp_ip[0:8] + struct.pack("B", (orb(tmp_ip[8]) ^ 0x2)) + tmp_ip[9:16]  # noqa: E501
                    elif underlayer.underlayer.fcf_destaddrmode == 2:
                        tmp_ip = LINK_LOCAL_PREFIX[0:8] + \
                            b"\x00\x00\x00\xff\xfe\x00" + \
                            struct.pack(">Q", underlayer.dest_addr)[6:]
                else:
                    # Most of the times, it's necessary the IEEE 802.15.4 data to extract this address  # noqa: E501
                    raise Exception('Unimplemented: IP Header is contained into IEEE 802.15.4 frame, in this case it\'s not available.')  # noqa: E501
            elif self.dam not in [0x1, 0x2]:
                warning("Unknown destiny address compression mode !")
        elif self.m == 1 and self.dac == 0:
            if self.dam == 0:
                raise Exception("unimplemented")
            elif self.dam == 1:
                tmp = b"\xff" + chb(tmp_ip[16 - destiny_addr_mode(self)])
                tmp_ip = tmp + b"\x00" * 9 + tmp_ip[-5:]
            elif self.dam == 2:
                tmp = b"\xff" + chb(tmp_ip[16 - destiny_addr_mode(self)])
                tmp_ip = tmp + b"\x00" * 11 + tmp_ip[-3:]
            else:  # self.dam == 3:
                tmp_ip = b"\xff\x02" + b"\x00" * 13 + tmp_ip[-1:]
        elif self.m == 1 and self.dac == 1:
            if self.dam == 0x0:
                raise Exception("Unimplemented: I didnt understand the 6lowpan specification")  # noqa: E501
            else:  # all the others values
                raise Exception("Reserved value by specification.")

        self.destinyAddr = inet_ntop(socket.AF_INET6, tmp_ip)
        return self.destinyAddr
开发者ID:plorinquer,项目名称:scapy,代码行数:56,代码来源:sixlowpan.py


示例8: post_build

 def post_build(self, p, pay):
     p += pay
     if self.Length is None:
         tmp_len = len(p)
         tmp_p = p[:6] + chb((tmp_len >> 8) & 0xff) + chb(tmp_len & 0xff)
         p = tmp_p + p[8:]
     if self.chksum is None:
         ck = checksum(p)
         p = p[:2] + chb(ck >> 8) + chb(ck & 0xff) + p[4:]
     return p
开发者ID:commial,项目名称:scapy,代码行数:10,代码来源:rsvp.py


示例9: post_build

 def post_build(self, p, pay):
     if self.chksum is None:
         if isinstance(self.underlayer, IP):
             ck = in4_chksum(112, self.underlayer, p)
         elif isinstance(self.underlayer, IPv6):
             ck = in6_chksum(112, self.underlayer, p)
         else:
             warning("No IP(v6) layer to compute checksum on VRRP. Leaving null")  # noqa: E501
             ck = 0
         p = p[:6] + chb(ck >> 8) + chb(ck & 0xff) + p[8:]
     return p
开发者ID:commial,项目名称:scapy,代码行数:11,代码来源:vrrp.py


示例10: enc

 def enc(cls, s):
     # /!\ this is DER encoding (bit strings are only zero-bit padded)
     s = raw(s)
     if len(s) % 8 == 0:
         unused_bits = 0
     else:
         unused_bits = 8 - len(s) % 8
         s += b"0" * unused_bits
     s = b"".join(chb(int(b"".join(chb(y) for y in x), 2))
                  for x in zip(*[iter(s)] * 8))
     s = chb(unused_bits) + s
     return chb(hash(cls.tag)) + BER_len_enc(len(s)) + s
开发者ID:commial,项目名称:scapy,代码行数:12,代码来源:ber.py


示例11: BER_id_enc

def BER_id_enc(n):
    if n < 256:
        # low-tag-number
        return chb(n)
    else:
        # high-tag-number
        s = BER_num_enc(n)
        tag = orb(s[0])             # first byte, as an int
        tag &= 0x07                 # reset every bit from 8 to 4
        tag <<= 5                   # move back the info bits on top
        tag |= 0x1f                 # pad with 1s every bit from 5 to 1
        return chb(tag) + s[1:]
开发者ID:commial,项目名称:scapy,代码行数:12,代码来源:ber.py


示例12: post_build

    def post_build(self, p, pay):
        """Called implicitly before a packet is sent to compute and place IGMP checksum.  # noqa: E501

        Parameters:
          self    The instantiation of an IGMP class
          p       The IGMP message in hex in network byte order
          pay     Additional payload for the IGMP message
        """
        p += pay
        if self.chksum is None:
            ck = checksum(p)
            p = p[:2] + chb(ck >> 8) + chb(ck & 0xff) + p[4:]
        return p
开发者ID:plorinquer,项目名称:scapy,代码行数:13,代码来源:igmp.py


示例13: BER_len_enc

def BER_len_enc(ll, size=0):
    if ll <= 127 and size == 0:
        return chb(ll)
    s = b""
    while ll or size > 0:
        s = chb(ll & 0xff) + s
        ll >>= 8
        size -= 1
    if len(s) > 127:
        raise BER_Exception(
            "BER_len_enc: Length too long (%i) to be encoded [%r]" %
            (len(s), s)
        )
    return chb(len(s) | 0x80) + s
开发者ID:commial,项目名称:scapy,代码行数:14,代码来源:ber.py


示例14: obfuscate

def obfuscate(pay, secret, session_id, version, seq):
    '''

    Obfuscation methodology from section 3.7
    https://tools.ietf.org/html/draft-ietf-opsawg-tacacs-06#section-3.7

    '''

    pad = b""
    curr_pad = b""

    # pad length must equal the payload to obfuscate.
    # pad = {MD5_1 [,MD5_2 [ ... ,MD5_n]]}

    while len(pad) < len(pay):

        msg = hashlib.md5()
        msg.update(struct.pack('!I', session_id))
        msg.update(secret.encode())
        msg.update(struct.pack('!BB', version, seq))
        msg.update(curr_pad)
        curr_pad = msg.digest()
        pad += curr_pad

    # Obf/Unobfuscation via XOR operation between plaintext and pad

    return b"".join(chb(orb(pad[i]) ^ orb(pay[i])) for i in range(len(pay)))
开发者ID:plorinquer,项目名称:scapy,代码行数:27,代码来源:tacacs.py


示例15: post_build

 def post_build(self, p, pay):
     p += pay
     optionlen = self.optionlen
     if optionlen is None:
         optionlen = (len(self.options) + 3) // 4
         p = chb(optionlen & 0x2f | orb(p[0]) & 0xc0) + p[1:]
     return p
开发者ID:plorinquer,项目名称:scapy,代码行数:7,代码来源:geneve.py


示例16: next

 def next(self):
     c = pcap_next_ex(self.pcap, byref(self.header), byref(self.pkt_data))  # noqa: E501
     if not c > 0:
         return
     ts = self.header.contents.ts.tv_sec + float(self.header.contents.ts.tv_usec) / 1000000  # noqa: E501
     pkt = b"".join(chb(i) for i in self.pkt_data[:self.header.contents.len])  # noqa: E501
     return ts, pkt
开发者ID:commial,项目名称:scapy,代码行数:7,代码来源:pcapdnet.py


示例17: _tls_del_pad

def _tls_del_pad(p):
    """
    Provided with a just decrypted TLSCiphertext (now a TLSPlaintext instance)
    p, the function removes the trailing padding found in p.data. It also
    performs some sanity checks on the padding (length, content, ...). False
    is returned if one of the check fails. Otherwise, True is returned,
    indicating that p.data and p.len have been updated.
    """

    if p.len < 1:
        warning("Message format is invalid (padding)")
        return False

    padlen = orb(p.data[-1])
    padsize = padlen + 1

    if p.len < padsize:
        warning("Invalid padding length")
        return False

    if p.data[-padsize:] != chb(padlen) * padsize:
        warning("Padding content is invalid %s", repr(p.data[-padsize:]))
        return False

    p.data = p.data[:-padsize]
    p.len -= padsize

    return True
开发者ID:plorinquer,项目名称:scapy,代码行数:28,代码来源:tools.py


示例18: post_build

 def post_build(self, p, pay):
     if self.headerLen is None:
         headerLen = len(p)
         if isinstance(self.payload, (USBpcapTransferIsochronous,
                                      USBpcapTransferInterrupt,
                                      USBpcapTransferControl)):
             headerLen += len(self.payload) - len(self.payload.payload)
         p = chb(headerLen) + p[1:]
     return p + pay
开发者ID:commial,项目名称:scapy,代码行数:9,代码来源:usb.py


示例19: post_build

 def post_build(self, p, pay):
     # This just forces destaddrmode to None for Ack frames.
     if self.fcf_frametype == 2 and self.fcf_destaddrmode != 0:
         self.fcf_destaddrmode = 0
         return p[:1] + \
             chb((self.fcf_srcaddrmode << 6) + (self.fcf_framever << 4)) \
             + p[2:] + pay
     else:
         return p + pay
开发者ID:commial,项目名称:scapy,代码行数:9,代码来源:dot15d4.py


示例20: BER_num_enc

def BER_num_enc(ll, size=1):
    x = []
    while ll or size > 0:
        x.insert(0, ll & 0x7f)
        if len(x) > 1:
            x[0] |= 0x80
        ll >>= 7
        size -= 1
    return b"".join(chb(k) for k in x)
开发者ID:commial,项目名称:scapy,代码行数:9,代码来源:ber.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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