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


Python netaddr.EUI属性代码示例

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


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

示例1: get_ipv6_addr_by_EUI64

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def get_ipv6_addr_by_EUI64(cidr, mac):
    """Generate a IPv6 addr by EUI-64 with CIDR and MAC

    :param str cidr: a IPv6 CIDR
    :param str mac: a MAC address
    :return: an IPv6 Address
    :rtype: netaddr.IPAddress
    """
    # Check if the prefix is IPv4 address
    is_ipv4 = netaddr.valid_ipv4(cidr)
    if is_ipv4:
        msg = "Unable to generate IP address by EUI64 for IPv4 prefix"
        raise TypeError(msg)
    try:
        eui64 = int(netaddr.EUI(mac).eui64())
        prefix = netaddr.IPNetwork(cidr)
        return netaddr.IPAddress(prefix.first + eui64 ^ (1 << 57))
    except (ValueError, netaddr.AddrFormatError):
        raise TypeError('Bad prefix or mac format for generating IPv6 '
                        'address by EUI-64: %(prefix)s, %(mac)s:'
                        % {'prefix': cidr, 'mac': mac})
    except TypeError:
        raise TypeError('Bad prefix type for generate IPv6 address by '
                        'EUI-64: %s' % cidr) 
开发者ID:openstack,项目名称:tempest-lib,代码行数:26,代码来源:data_utils.py

示例2: parse

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def parse(cls, value, iswithdraw=False):
        route = dict()
        # rd
        offset = 8
        route['rd'] = cls.parse_rd(value[0:offset])
        # esi
        route['esi'] = int(binascii.b2a_hex(value[offset: offset+10]), 16)
        offset += 10
        # ethernet tag id
        route['eth_tag_id'] = struct.unpack('!I', value[offset: offset+4])[0]
        offset += 5
        # mac address
        route['mac'] = str(netaddr.EUI(int(binascii.b2a_hex(value[offset: offset+6]), 16)))
        offset += 6
        ip_addr_len = ord(value[offset: offset + 1])
        offset += 1
        # ip address
        if ip_addr_len != 0:
            route['ip'] = str(netaddr.IPAddress(
                int(binascii.b2a_hex(value[offset: offset + int(ip_addr_len / 8)]), 16)))
            offset += int(ip_addr_len / 8)
        # label
        route['label'] = MPLSVPN.parse_mpls_label_stack(value[offset:])
        return route 
开发者ID:smartbgp,项目名称:yabgp,代码行数:26,代码来源:evpn.py

示例3: __init__

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def __init__(self,  id=0, name=None, mac_address=None, ip_address=None,
                        connected_ssid=None, inactivity_time=None,
                        rx_packets=None, tx_packets=None,
                        rx_bitrate=None, tx_bitrate=None,
                        signal=None):

        self.id = id
        self.name = name
        self.mac_address = mac_address
        self.ip_address = ip_address
        self.connected_ssid = connected_ssid
        self.inactivity_time = inactivity_time
        self.rx_packets = rx_packets
        self.tx_packets = tx_packets
        self.tx_bitrate = tx_bitrate
        self.rx_bitrate = rx_bitrate
        self.signal = signal
        self.vendor = None
        try:
            self.vendor = EUI(mac_address).oui.registration().org      # OUI - Organizational Unique Identifier
        except Exception:
            pass 
开发者ID:Esser420,项目名称:EvilTwinFramework,代码行数:24,代码来源:aplauncher.py

示例4: run

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def run(self):
        mac = netaddr.EUI(int(self.arguments.mac) if self.arguments.mac.isdigit() else self.arguments.mac)
        info = mac.info["OUI"]
        print(f"[i] Media Access Control (MAC) Address Lookup Results For {mac}:")
        print(f" -  Extended Unique Identifier 64:       {mac.eui64()}", dark=True)
        print(f" -  Modified EUI64 Address:              {mac.modified_eui64()}", dark=True)
        print(f" -  Individual Access Block [IAB]:       {mac.iab if mac.is_iab() else 'Not an IAB'}", dark=True)
        print(f" -  Organizationally Unique Identifier:  {mac.oui}", dark=True)
        print(f" -  Extended Identifier [EI]:            {mac.ei}", dark=True)
        print(f" -  Local Link IPv6 Address:             {mac.ipv6_link_local()}", dark=True)
        print(f" -  Vendor Info.:")
        print(f"    - Organization: {info['org']}", dark=True)
        print( "    - Address:      {}".format("\n                    ".join(info["address"])), dark=True)
        print(f" -  OUI Info.:")
        print(f"    - Version: {mac.version}", dark=True)
        print(f"    - Offset:  {info['offset']}", dark=True)
        print(f"    - Size:    {info['size']}", dark=True)
        print(f"    - IDX:     {info['idx']}", dark=True)
        print(f"    - OUI:     {info['oui']}", dark=True)
        print(f" -  Packed Address:          {mac.packed}", dark=True)
        print(f" -  Hexadecimal Address:     {hex(mac)}", dark=True)
        print(f" -  48-bit Positive Integer: {mac.value}", dark=True)
        print(f" -  Octets:                  {', '.join(str(n) for n in mac.words)}", dark=True) 
开发者ID:black-security,项目名称:cyber-security-framework,代码行数:25,代码来源:mac-lookup.py

示例5: get_device_names

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def get_device_names(device):
    mac_vendor = None
    try:
        mac_vendor = EUI(device.mac).oui.registration().org
    except Exception:
        pass

    elems = [device.hostname]
    elems.extend([x.model for x in device.user_agent.all()])
    elems.append(mac_vendor)
    elems.append(device.mac)
    names = []
    # make unique sorted list
    [names.append(x) for x in elems if x not in names]

    return filter(lambda x: x not in IGNORE, names) 
开发者ID:usableprivacy,项目名称:upribox,代码行数:18,代码来源:base_extras.py

示例6: get_expected_matches

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def get_expected_matches(self):
        return [
            {
                'reg6': test_app_base.fake_local_port2.unique_key,
                'eth_src': netaddr.EUI('fa:16:3e:00:00:01'),
                'eth_type': os_ken.lib.packet.ether_types.ETH_TYPE_IP,
                'ipv4_src': netaddr.IPAddress('192.168.18.3'),
            }, {
                'reg7': 33,
                'eth_type': os_ken.lib.packet.ether_types.ETH_TYPE_IP,
            }, {
                'reg6': test_app_base.fake_local_port2.unique_key,
                'eth_src': netaddr.EUI('fa:16:3e:00:00:01'),
                'eth_type': os_ken.lib.packet.ether_types.ETH_TYPE_ARP,
                'arp_sha': netaddr.EUI('fa:16:3e:00:00:01'),
                'arp_spa': netaddr.IPAddress('192.168.18.3'),
            }, {
                'reg7': 33,
                'eth_type': os_ken.lib.packet.ether_types.ETH_TYPE_ARP,
            }
        ] 
开发者ID:openstack,项目名称:dragonflow,代码行数:23,代码来源:test_trunk_app.py

示例7: get_expected_actions

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def get_expected_actions(self):
        return [
            [
                SettingMock(reg6=33),
                SettingMock(metadata=17),
                SettingMock(eth_src=netaddr.EUI('fa:16:3e:00:00:01')),
                self.app.parser.NXActionResubmit(),
            ], [
                SettingMock(eth_dst=test_app_base.fake_local_port2.mac),
                SettingMock(reg7=test_app_base.fake_local_port2.unique_key),
                self.app.parser.NXActionResubmit(),
            ], [
                SettingMock(reg6=33),
                SettingMock(metadata=17),
                SettingMock(eth_src=netaddr.EUI('fa:16:3e:00:00:01')),
                SettingMock(arp_sha=netaddr.EUI('fa:16:3e:00:00:01')),
                self.app.parser.NXActionResubmit(),
            ], [
                SettingMock(eth_dst=test_app_base.fake_local_port2.mac),
                SettingMock(arp_tha=test_app_base.fake_local_port2.mac),
                SettingMock(reg7=test_app_base.fake_local_port2.unique_key),
                self.app.parser.NXActionResubmit(),
            ]
        ] 
开发者ID:openstack,项目名称:dragonflow,代码行数:26,代码来源:test_trunk_app.py

示例8: _get_another_local_lport

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def _get_another_local_lport(self):
        fake_local_port = test_app_base.make_fake_local_port(
            id='fake_port2',
            topic='fake_tenant1',
            name='',
            unique_key=5,
            version=2,
            ips=[netaddr.IPAddress('10.0.0.10'),
                 netaddr.IPAddress('2222:2222::2')],
            subnets=['fake_subnet1'],
            macs=[netaddr.EUI('fa:16:3e:8c:2e:12')],
            lswitch='fake_switch1',
            security_groups=['fake_security_group_id1'],
            allowed_address_pairs=[],
            port_security_enabled=True,
            device_owner='compute:None',
            device_id='fake_device_id',
            # 'binding_profile': {},
            # 'binding_vnic_type': 'normal',
        )
        return fake_local_port 
开发者ID:openstack,项目名称:dragonflow,代码行数:23,代码来源:test_sg_app.py

示例9: is_valid_macaddress

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def is_valid_macaddress(self, value_to_check):
        """
        Passed a prospective MAC address and check that
        it is valid.
        Return 1 for is valid IP address and 0 for not valid
        """
        try:
            result = EUI(value_to_check)
            if result.version != 48:
                self.logger.debug("Check of is_valid_macaddress on %s "
                        "returned false", value_to_check)
                return 0
        except:
            self.logger.debug("Check of "
                    "is_valid_macaddress on %s raised an exception",
                    value_to_check)
            return 0
        return 1 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:20,代码来源:tc_static.py

示例10: is_match_macaddress

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def is_match_macaddress(self, value_to_check1, value_to_check2):
        """
        Passed a two prospective MAC addresses and check to
        see if they are the same address.
        Return 1 for both the same MAC address and 0 for different
        """
        try:
            if not EUI(value_to_check1) == EUI(value_to_check2):
                self.logger.debug("Check of "
                        "is_match_macaddress on %s vs %s returned false",
                        value_to_check1, value_to_check2)
                return 0
        except:
            self.logger.debug("Check of "
                    "is_match_macaddress on %s vs %s raised an exception",
                    value_to_check1, value_to_check2)
            return 0
        return 1 
开发者ID:mattjhayes,项目名称:nmeta,代码行数:20,代码来源:tc_static.py

示例11: get_eui_organization

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def get_eui_organization(eui):
    """Returns the registered organization for the specified EUI, if it can be
    determined. Otherwise, returns None.

    :param eui:A `netaddr.EUI` object.
    """
    try:
        registration = eui.oui.registration()
        # Note that `registration` is not a dictionary, so we can't use .get().
        return registration["org"]
    except UnicodeError:
        # See bug #1628761. Due to corrupt data in the OUI database, and/or
        # the fact that netaddr assumes all the data is ASCII, sometimes
        # netaddr will raise an exception during this process.
        return None
    except IndexError:
        # See bug #1748031; this is another way netaddr can fail.
        return None
    except NotRegisteredError:
        # This could happen for locally-administered MACs.
        return None 
开发者ID:maas,项目名称:maas,代码行数:23,代码来源:network.py

示例12: test_properties

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def test_properties(self):
        pkt_sender_mac = "01:02:03:04:05:06"
        pkt_sender_ip = "192.168.0.1"
        pkt_target_ip = "192.168.0.2"
        pkt_target_mac = "00:00:00:00:00:00"
        eth_src = "02:03:04:05:06:07"
        eth_dst = "ff:ff:ff:ff:ff:ff"
        arp_packet = make_arp_packet(
            pkt_sender_ip, pkt_sender_mac, pkt_target_ip, pkt_target_mac
        )
        arp = ARP(
            arp_packet,
            src_mac=hex_str_to_bytes(eth_src),
            dst_mac=hex_str_to_bytes(eth_dst),
        )
        self.assertThat(arp.source_eui, Equals(EUI(pkt_sender_mac)))
        self.assertThat(arp.target_eui, Equals(EUI(pkt_target_mac)))
        self.assertThat(arp.source_ip, Equals(IPAddress(pkt_sender_ip)))
        self.assertThat(arp.target_ip, Equals(IPAddress(pkt_target_ip))) 
开发者ID:maas,项目名称:maas,代码行数:21,代码来源:test_arp.py

示例13: test_bindings__returns_sender_for_request

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def test_bindings__returns_sender_for_request(self):
        pkt_sender_mac = "01:02:03:04:05:06"
        pkt_sender_ip = "192.168.0.1"
        pkt_target_ip = "192.168.0.2"
        pkt_target_mac = "00:00:00:00:00:00"
        arp = ARP(
            make_arp_packet(
                pkt_sender_ip,
                pkt_sender_mac,
                pkt_target_ip,
                pkt_target_mac,
                op=ARP_OPERATION.REQUEST,
            )
        )
        self.assertItemsEqual(
            arp.bindings(), [(IPAddress(pkt_sender_ip), EUI(pkt_sender_mac))]
        ) 
开发者ID:maas,项目名称:maas,代码行数:19,代码来源:test_arp.py

示例14: test_bindings__returns_sender_and_target_for_reply

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def test_bindings__returns_sender_and_target_for_reply(self):
        pkt_sender_mac = "01:02:03:04:05:06"
        pkt_sender_ip = "192.168.0.1"
        pkt_target_ip = "192.168.0.2"
        pkt_target_mac = "02:03:04:05:06:07"
        arp = ARP(
            make_arp_packet(
                pkt_sender_ip,
                pkt_sender_mac,
                pkt_target_ip,
                pkt_target_mac,
                op=ARP_OPERATION.REPLY,
            )
        )
        self.assertItemsEqual(
            arp.bindings(),
            [
                (IPAddress(pkt_sender_ip), EUI(pkt_sender_mac)),
                (IPAddress(pkt_target_ip), EUI(pkt_target_mac)),
            ],
        ) 
开发者ID:maas,项目名称:maas,代码行数:23,代码来源:test_arp.py

示例15: test_bindings__skips_null_target_ip_in_reply

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import EUI [as 别名]
def test_bindings__skips_null_target_ip_in_reply(self):
        pkt_sender_mac = "01:02:03:04:05:06"
        pkt_sender_ip = "192.168.0.1"
        pkt_target_ip = "0.0.0.0"
        pkt_target_mac = "02:03:04:05:06:07"
        arp = ARP(
            make_arp_packet(
                pkt_sender_ip,
                pkt_sender_mac,
                pkt_target_ip,
                pkt_target_mac,
                op=ARP_OPERATION.REPLY,
            )
        )
        self.assertItemsEqual(
            arp.bindings(), [(IPAddress(pkt_sender_ip), EUI(pkt_sender_mac))]
        ) 
开发者ID:maas,项目名称:maas,代码行数:19,代码来源:test_arp.py


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