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

Python six.itervalues函数代码示例

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

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



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

示例1: auth_encrypt

    def auth_encrypt(self, P, A, seq_num):
        """
        Encrypt the data, and append the computed authentication code.
        TLS 1.3 does not use additional data, but we leave this option to the
        user nonetheless.

        Note that the cipher's authentication tag must be None when encrypting.
        """
        if False in six.itervalues(self.ready):
            raise CipherError(P, A)

        if hasattr(self, "pc_cls"):
            self._cipher.mode._tag = None
            self._cipher.mode._initialization_vector = self._get_nonce(seq_num)
            encryptor = self._cipher.encryptor()
            encryptor.authenticate_additional_data(A)
            res = encryptor.update(P) + encryptor.finalize()
            res += encryptor.tag
        else:
            if (conf.crypto_valid_advanced and
                    isinstance(self._cipher, AESCCM)):
                res = self._cipher.encrypt(self._get_nonce(seq_num), P, A,
                                           tag_length=self.tag_len)
            else:
                res = self._cipher.encrypt(self._get_nonce(seq_num), P, A)
        return res
开发者ID:plorinquer,项目名称:scapy,代码行数:26,代码来源:cipher_aead.py


示例2: _read_routes_xp

def _read_routes_xp():
    # The InterfaceIndex in Win32_IP4RouteTable does not match the
    # InterfaceIndex in Win32_NetworkAdapter under some platforms
    # (namely Windows XP): let's try an IP association
    routes = []
    partial_routes = []
    # map local IP addresses to interfaces
    local_addresses = {iface.ip: iface for iface in six.itervalues(IFACES)}
    iface_indexes = {}
    for line in exec_query(['Get-WmiObject', 'Win32_IP4RouteTable'],
                           ['Name', 'Mask', 'NextHop', 'InterfaceIndex', 'Metric1']):
        if line[2] in local_addresses:
            iface = local_addresses[line[2]]
            # This gives us an association InterfaceIndex <-> interface
            iface_indexes[line[3]] = iface
            routes.append((atol(line[0]), atol(line[1]), "0.0.0.0", iface,
                           iface.ip, int(line[4])))
        else:
            partial_routes.append((atol(line[0]), atol(line[1]), line[2],
                                   line[3], int(line[4])))
    for dst, mask, gw, ifidx, metric in partial_routes:
        if ifidx in iface_indexes:
            iface = iface_indexes[ifidx]
            routes.append((dst, mask, gw, iface, iface.ip, metric))
    return routes
开发者ID:dark-lbp,项目名称:scapy,代码行数:25,代码来源:__init__.py


示例3: getfield

 def getfield(self, pkt, s):
     if (pkt.tls_session.rcs.cipher.type != "aead" and
             False in six.itervalues(pkt.tls_session.rcs.cipher.ready)):
         # XXX Find a more proper way to handle the still-encrypted case
         return s, b""
     tmp_len = pkt.tls_session.rcs.mac_len
     return s[tmp_len:], self.m2i(pkt, s[:tmp_len])
开发者ID:commial,项目名称:scapy,代码行数:7,代码来源:basefields.py


示例4: dev_from_pcapname

 def dev_from_pcapname(self, pcap_name):
     """Return Windows device name for given pcap device name."""
     try:
         return next(iface for iface in six.itervalues(self)
                     if iface.pcap_name == pcap_name)
     except StopIteration:
         raise ValueError("Unknown pypcap network interface %r" % pcap_name)
开发者ID:plorinquer,项目名称:scapy,代码行数:7,代码来源:__init__.py


示例5: __init__

 def __init__(self, objlist=None):
     self.objlist = [
         x._asn1_obj
         for x in six.itervalues(ASN1_Class_UNIVERSAL.__rdict__)
         if hasattr(x, "_asn1_obj")
     ] if objlist is None else objlist
     self.chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"  # noqa: E501
开发者ID:plorinquer,项目名称:scapy,代码行数:7,代码来源:asn1.py


示例6: _get_valid_guid

def _get_valid_guid():
    if scapy.consts.LOOPBACK_INTERFACE:
        return scapy.consts.LOOPBACK_INTERFACE.guid
    else:
        for i in six.itervalues(IFACES):
            if not i.is_invalid():
                return i.guid
开发者ID:dark-lbp,项目名称:scapy,代码行数:7,代码来源:__init__.py


示例7: dev_from_name

 def dev_from_name(self, name):
     """Return the first pcap device name for a given Windows
     device name.
     """
     for iface in six.itervalues(self):
         if iface.name == name:
             return iface
     raise ValueError("Unknown network interface %r" % name)
开发者ID:dark-lbp,项目名称:scapy,代码行数:8,代码来源:__init__.py


示例8: dev_from_name

 def dev_from_name(self, name):
     """Return the first pcap device name for a given Windows
     device name.
     """
     try:
         return next(iface for iface in six.itervalues(self)
                     if iface.name == name)
     except StopIteration:
         raise ValueError("Unknown network interface %r" % name)
开发者ID:plorinquer,项目名称:scapy,代码行数:9,代码来源:__init__.py


示例9: encrypt

 def encrypt(self, data):
     """
     Encrypt the data. Also, update the cipher iv. This is needed for SSLv3
     and TLS 1.0. For TLS 1.1/1.2, it is overwritten in TLS.post_build().
     """
     if False in six.itervalues(self.ready):
         raise CipherError(data)
     encryptor = self._cipher.encryptor()
     tmp = encryptor.update(data) + encryptor.finalize()
     self.iv = tmp[-self.block_size:]
     return tmp
开发者ID:6WIND,项目名称:scapy,代码行数:11,代码来源:cipher_block.py


示例10: randval

 def randval(self):
     randchoices = []
     for p in six.itervalues(self.choices):
         if hasattr(p, "ASN1_root"):   # should be ASN1_Packet class
             randchoices.append(packet.fuzz(p()))
         elif hasattr(p, "ASN1_tag"):
             if isinstance(p, type):       # should be (basic) ASN1F_field class  # noqa: E501
                 randchoices.append(p("dummy", None).randval())
             else:                     # should be ASN1F_PACKET instance
                 randchoices.append(p.randval())
     return RandChoice(*randchoices)
开发者ID:commial,项目名称:scapy,代码行数:11,代码来源:asn1fields.py


示例11: dev_from_index

 def dev_from_index(self, if_index):
     """Return interface name from interface index"""
     try:
         return next(iface for iface in six.itervalues(self)
                     if iface.win_index == str(if_index))
     except StopIteration:
         if str(if_index) == "1":
             # Test if the loopback interface is set up
             if isinstance(scapy.consts.LOOPBACK_INTERFACE, NetworkInterface):  # noqa: E501
                 return scapy.consts.LOOPBACK_INTERFACE
         raise ValueError("Unknown network interface index %r" % if_index)
开发者ID:plorinquer,项目名称:scapy,代码行数:11,代码来源:__init__.py


示例12: graph

    def graph(self, **kargs):
        s = 'digraph "%s" {\n'  % self.__class__.__name__
        
        se = "" # Keep initial nodes at the begining for better rendering
        for st in six.itervalues(self.states):
            if st.atmt_initial:
                se = ('\t"%s" [ style=filled, fillcolor=blue, shape=box, root=true];\n' % st.atmt_state)+se
            elif st.atmt_final:
                se += '\t"%s" [ style=filled, fillcolor=green, shape=octagon ];\n' % st.atmt_state
            elif st.atmt_error:
                se += '\t"%s" [ style=filled, fillcolor=red, shape=octagon ];\n' % st.atmt_state
        s += se

        for st in six.itervalues(self.states):
            for n in st.atmt_origfunc.__code__.co_names+st.atmt_origfunc.__code__.co_consts:
                if n in self.states:
                    s += '\t"%s" -> "%s" [ color=green ];\n' % (st.atmt_state,n)
            

        for c,k,v in ([("purple",k,v) for k,v in self.conditions.items()]+
                      [("red",k,v) for k,v in self.recv_conditions.items()]+
                      [("orange",k,v) for k,v in self.ioevents.items()]):
            for f in v:
                for n in f.__code__.co_names+f.__code__.co_consts:
                    if n in self.states:
                        l = f.atmt_condname
                        for x in self.actions[f.atmt_condname]:
                            l += "\\l>[%s]" % x.__name__
                        s += '\t"%s" -> "%s" [label="%s", color=%s];\n' % (k,n,l,c)
        for k,v in six.iteritems(self.timeout):
            for t,f in v:
                if f is None:
                    continue
                for n in f.__code__.co_names+f.__code__.co_consts:
                    if n in self.states:
                        l = "%s/%.1fs" % (f.atmt_condname,t)                        
                        for x in self.actions[f.atmt_condname]:
                            l += "\\l>[%s]" % x.__name__
                        s += '\t"%s" -> "%s" [label="%s",color=blue];\n' % (k,n,l)
        s += "}\n"
        return do_graph(s, **kargs)
开发者ID:mcpat,项目名称:scapy,代码行数:41,代码来源:automaton.py


示例13: decrypt

 def decrypt(self, data):
     """
     Decrypt the data. Also, update the cipher iv. This is needed for SSLv3
     and TLS 1.0. For TLS 1.1/1.2, it is overwritten in TLS.pre_dissect().
     If we lack the key, we raise a CipherError which contains the input.
     """
     if False in six.itervalues(self.ready):
         raise CipherError(data)
     decryptor = self._cipher.decryptor()
     tmp = decryptor.update(data) + decryptor.finalize()
     self.iv = data[-self.block_size:]
     return tmp
开发者ID:6WIND,项目名称:scapy,代码行数:12,代码来源:cipher_block.py


示例14: post_dissection

    def post_dissection(self, r):
        if not self.tls_session.frozen and self.server_share.pubkey:
            # if there is a pubkey, we assume the crypto library is ok
            pubshare = self.tls_session.tls13_server_pubshare
            if len(pubshare) > 0:
                pkt_info = r.firstlayer().summary()
                log_runtime.info("TLS: overwriting previous server key share [%s]", pkt_info)  # noqa: E501
            group_name = _tls_named_groups[self.server_share.group]
            pubshare[group_name] = self.server_share.pubkey

            if group_name in self.tls_session.tls13_client_privshares:
                pubkey = self.server_share.pubkey
                privkey = self.tls_session.tls13_client_privshares[group_name]
                if group_name in six.itervalues(_tls_named_ffdh_groups):
                    pms = privkey.exchange(pubkey)
                elif group_name in six.itervalues(_tls_named_curves):
                    if group_name == "x25519":
                        pms = privkey.exchange(pubkey)
                    else:
                        pms = privkey.exchange(ec.ECDH(), pubkey)
                self.tls_session.tls13_dhe_secret = pms
        return super(TLS_Ext_KeyShare_SH, self).post_dissection(r)
开发者ID:commial,项目名称:scapy,代码行数:22,代码来源:keyexchange_tls13.py


示例15: auth_decrypt

    def auth_decrypt(self, A, C, seq_num=None, add_length=True):
        """
        Decrypt the data and authenticate the associated data (i.e. A).
        If the verification fails, an AEADTagError is raised. It is the user's
        responsibility to catch it if deemed useful. If we lack the key, we
        raise a CipherError which contains the encrypted input.

        Note that we add the TLSCiphertext length to A although we're supposed
        to add the TLSCompressed length. Fortunately, they are the same,
        but the specifications actually messed up here. :'(

        The 'add_length' switch should always be True for TLS, but we provide
        it anyway (mostly for test cases, hum).

        The 'seq_num' should never be used here, it is only a safeguard needed
        because one cipher (ChaCha20Poly1305) using TLS 1.2 logic in record.py
        actually is a _AEADCipher_TLS13 (even though others are not).
        """
        nonce_explicit_str, C, mac = (C[:self.nonce_explicit_len],
                                      C[self.nonce_explicit_len:-self.tag_len],
                                      C[-self.tag_len:])

        if False in six.itervalues(self.ready):
            raise CipherError(nonce_explicit_str, C, mac)

        self.nonce_explicit = pkcs_os2ip(nonce_explicit_str)
        if add_length:
            A += struct.pack("!H", len(C))

        if hasattr(self, "pc_cls"):
            self._cipher.mode._initialization_vector = self._get_nonce()
            self._cipher.mode._tag = mac
            decryptor = self._cipher.decryptor()
            decryptor.authenticate_additional_data(A)
            P = decryptor.update(C)
            try:
                decryptor.finalize()
            except InvalidTag:
                raise AEADTagError(nonce_explicit_str, P, mac)
        else:
            try:
                if isinstance(self._cipher, AESCCM):
                    P = self._cipher.decrypt(self._get_nonce(), C + mac, A,
                                             tag_length=self.tag_len)
                else:
                    P = self._cipher.decrypt(self._get_nonce(), C + mac, A)
            except InvalidTag:
                raise AEADTagError(nonce_explicit_str,
                                   "<unauthenticated data>",
                                   mac)
        return nonce_explicit_str, P, mac
开发者ID:plorinquer,项目名称:scapy,代码行数:51,代码来源:cipher_aead.py


示例16: getfield

    def getfield(self, pkt, s):
        """
        If the decryption of the content did not fail with a CipherError,
        we begin a loop on the clear content in order to get as much messages
        as possible, of the type advertised in the record header. This is
        notably important for several TLS handshake implementations, which
        may for instance pack a server_hello, a certificate, a
        server_key_exchange and a server_hello_done, all in one record.
        Each parsed message may update the TLS context through their method
        .post_dissection_tls_session_update().

        If the decryption failed with a CipherError, presumably because we
        missed the session keys, we signal it by returning a
        _TLSEncryptedContent packet which simply contains the ciphered data.
        """
        tmp_len = self.length_from(pkt)
        lst = []
        ret = b""
        remain = s
        if tmp_len is not None:
            remain, ret = s[:tmp_len], s[tmp_len:]

        if remain == b"":
            if (((pkt.tls_session.tls_version or 0x0303) > 0x0200) and
                    hasattr(pkt, "type") and pkt.type == 23):
                return ret, [TLSApplicationData(data=b"")]
            else:
                return ret, [Raw(load=b"")]

        if False in six.itervalues(pkt.tls_session.rcs.cipher.ready):
            return ret, _TLSEncryptedContent(remain)
        else:
            while remain:
                raw_msg = remain
                p = self.m2i(pkt, remain)
                if Padding in p:
                    pad = p[Padding]
                    remain = pad.load
                    del(pad.underlayer.payload)
                    if len(remain) != 0:
                        raw_msg = raw_msg[:-len(remain)]
                else:
                    remain = b""

                if isinstance(p, _GenericTLSSessionInheritance):
                    if not p.tls_session.frozen:
                        p.post_dissection_tls_session_update(raw_msg)

                lst.append(p)
            return remain + ret, lst
开发者ID:commial,项目名称:scapy,代码行数:50,代码来源:record.py


示例17: i2repr

    def i2repr(self, pkt, x):
        v = self.depends_on(pkt)
        if v in self.names:
            these_names = self.names[v]
        else:
            these_names = {}

        r = set()
        for flag_set in x:
            for i in six.itervalues(these_names):
                if i.short == flag_set:
                    r.add("{} ({})".format(i.long, i.short))
                    break
            else:
                r.add(flag_set)
        return repr(r)
开发者ID:martingalloar,项目名称:scapy,代码行数:16,代码来源:fields.py


示例18: sndrcvflood

def sndrcvflood(pks, pkt, inter=0, verbose=None, chainCC=False, prn=lambda x: x):
    if not verbose:
        verbose = conf.verb
    if not isinstance(pkt, Gen):
        pkt = SetGen(pkt)
    tobesent = [p for p in pkt]
    received = plist.SndRcvList()
    seen = {}

    stopevent = threading.Event()
    count_packets = six.moves.queue.Queue()

    def send_in_loop(tobesent, stopevent, count_packets=count_packets):
        """Infinite generator that produces the same packet until stopevent is triggered."""
        while True:
            for p in tobesent:
                if stopevent.is_set():
                    raise StopIteration()
                count_packets.put(0)
                yield p

    infinite_gen = send_in_loop(tobesent, stopevent)

    # We don't use _sndrcv_snd verbose (it messes the logs up as in a thread that ends after recieving)
    thread = threading.Thread(
        target=_sndrcv_snd,
        args=(pks, None, inter, False, infinite_gen, stopevent),
    )
    thread.start()

    hsent, ans, nbrecv, notans = _sndrcv_rcv(pks, tobesent, stopevent, 0, len(tobesent), verbose, chainCC, False)
    thread.join()
    remain = list(itertools.chain(*six.itervalues(hsent)))
    # Apply prn
    ans = [(x, prn(y)) for (x, y) in ans]

    if verbose:
        print("\nReceived %i packets, got %i answers, remaining %i packets. Sent a total of %i packets." % (nbrecv+len(ans), len(ans), notans, count_packets.qsize()))
    count_packets.empty()
    del count_packets

    return plist.SndRcvList(ans), plist.PacketList(remain, "Unanswered")
开发者ID:6WIND,项目名称:scapy,代码行数:42,代码来源:sendrecv.py


示例19: any2i

    def any2i(self, pkt, x):
        assert isinstance(x, six.integer_types + (set,)), 'set expected'

        if pkt is not None:
            if isinstance(x, six.integer_types):
                x = self.m2i(pkt, x)
            else:
                v = self.depends_on(pkt)
                if v is not None:
                    assert v in self.names, 'invalid dependency'
                    these_names = self.names[v]
                    s = set()
                    for i in x:
                        for val in six.itervalues(these_names):
                            if val.short == i:
                                s.add(i)
                                break
                        else:
                            assert False, 'Unknown flag "{}" with this dependency'.format(i)
                            continue
                    x = s
        return x
开发者ID:martingalloar,项目名称:scapy,代码行数:22,代码来源:fields.py


示例20: values

 def values(self):
     if self.timeout is None:
         return list(six.itervalues(self))
     t0 = time.time()
     return [v for (k, v) in six.iteritems(self.__dict__) if t0 - self._timetable[k] < self.timeout]  # noqa: E501
开发者ID:commial,项目名称:scapy,代码行数:5,代码来源:config.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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