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


Python netaddr.AddrFormatError方法代码示例

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


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

示例1: ip_address_from_address

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def ip_address_from_address(address):
    try:
        ip_address = netaddr.IPAddress(address)
    except ValueError as e:
        # address contains a CIDR prefix, netmask, or hostmask.
        e.message = ('invalid IP address: %(address)s (detected CIDR, netmask,'
                     ' hostmask, or subnet)') % {'address': address}
        raise
    except netaddr.AddrFormatError as e:
        # address is not an IP address represented in an accepted string
        # format.
        e.message = ("invalid IP address: '%(address)s' (failed to detect a"
                     " valid IP address)") % {'address': address}
        raise

    if ip_address.version == 4:
        return ip_address
    else:
        raise NotSupported(
            ('invalid IP address: %(address)s (Internet Protocol version'
             ' %(version)s is not supported)') % {
                'address': address,
                'version': ip_address.version}) 
开发者ID:dsp-jetpack,项目名称:JetPack,代码行数:25,代码来源:discover_nodes.py

示例2: ip_network_from_address

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def ip_network_from_address(address):
    try:
        ip_network = netaddr.IPNetwork(address)
    except netaddr.AddrFormatError as e:
        # address is not an IP address represented in an accepted string
        # format.
        e.message = ("invalid IP network: '%(address)s' (failed to detect a"
                     " valid IP network)") % {
            'address': address}
        raise

    if ip_network.version == 4:
        return ip_network
    else:
        raise NotSupported(
            ('invalid IP network: %(address)s (Internet Protocol version'
             ' %(version)s is not supported)') % {
                'address': address,
                'version': ip_network.version}) 
开发者ID:dsp-jetpack,项目名称:JetPack,代码行数:21,代码来源:discover_nodes.py

示例3: get_ipv6_addr_by_EUI64

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [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

示例4: auto_select_target

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def auto_select_target(target, output=None):
    """Auto selection logic"""
    print "Target: %s" % target
    try:
        inp=IPAddress(target);
        if inp.is_private() or inp.is_loopback():
            print "Internal IP Detected : Skipping"
            sys.exit()
        else:
            print "Looks like an IP, running ipOsint...\n"
            ipOsint.run(target, output)
    except SystemExit:
        print "exiting"
    except AddrFormatError:
        if re.match('[^@]+@[^@]+\.[^@]+', target):
            print "Looks like an EMAIL, running emailOsint...\n"
            emailOsint.run(target, output)
        elif get_tld(target, fix_protocol=True,fail_silently=True) is not None:
            print "Looks like a DOMAIN, running domainOsint...\n"
            domainOsint.run(target, output)
        else:
            print "Nothing Matched assuming username, running usernameOsint...\n"
            usernameOsint.run(target, output)
    except:
        print "Unknown Error Occured" 
开发者ID:dvopsway,项目名称:datasploit,代码行数:27,代码来源:datasploit.py

示例5: __init__

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def __init__(self, gateway, targets, interface, myip, mymac):

        try:
            self.gateway = str(IPAddress(gateway))
        except AddrFormatError as e:
            print "[-] Select a valid IP address as gateway"
        iptables()
        set_ip_forwarding(1)
        self.gateway_mac = None
        self.range = False
        self.targets = self.get_range(targets)
        self.send = True
        self.interval = 3
        self.interface = interface
        self.myip = myip
        self.mymac = mymac
        self.socket = conf.L3socket(iface=self.interface)
        self.socket2 = conf.L2socket(iface=self.interface) 
开发者ID:m4n3dw0lf,项目名称:pythem,代码行数:20,代码来源:arpoisoner.py

示例6: tcppwn

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def tcppwn(self, payload):
        try:
            self.target = str(IPAddress(self.target))
        except AddrFormatError as e:
            try:
                self.target = gethostbyname(self.target)
            except Exception as e:
                print "[-] Select a valid IP address or domain name as target."
                print "[!] Exception caught: {}".format(e)
                return

        try:
            self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.socket.settimeout(4)
            self.socket.connect((self.target, self.port))
            self.socket.send(payload)
            while True:
                self.socket.recv(1024)
        except KeyboardInterrupt:
            return

        except Exception as e:
            if 'Connection refused' in e:
                print "[-] Connection refused."
                return 
开发者ID:m4n3dw0lf,项目名称:pythem,代码行数:27,代码来源:xploit.py

示例7: _validate_ip_addrs

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def _validate_ip_addrs(ip_addrs, ip_version=None):
    if not isinstance(ip_addrs, list):
        raise IsolatorException(
            "IP addresses must be provided as JSON list, not: %s" %
            type(ip_addrs))
    validated_ip_addrs = []
    for ip_addr in ip_addrs:
        try:
            ip = IPAddress(ip_addr)
        except AddrFormatError:
            raise IsolatorException("IP address could not be parsed: %s" %
                                    ip_addr)

        if ip_version and ip.version != ip_version:
            raise IsolatorException("IPv%d address must not be placed in IPv%d"
                                    " address field." %
                                    (ip.version, ip_version))
        else:
            validated_ip_addrs.append(ip)
    return validated_ip_addrs 
开发者ID:projectcalico,项目名称:netmodules-plugin,代码行数:22,代码来源:calico_mesos.py

示例8: _apply_interface_vlan_data

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def _apply_interface_vlan_data(self, vlans):
        config = self._fetch_interface_vlans_config(vlans)

        for interface in split_on_dedent(config):
            if regex.match("^.*Vlan(\d+)$", interface[0]):
                vlan = _find_vlan_by_number(vlans, regex[0])
                for line in interface[1:]:
                    if regex.match(" *ip helper-address (.*)", line):
                        try:
                            vlan.dhcp_relay_servers.append(IPAddress(regex[0]))
                        except AddrFormatError:
                            self.logger.warning(
                                'Unsupported IP Helper address found in Vlan {} : {}'.format(vlan.number, regex[0]))
                    if regex.match(" *ip virtual-router address (.*)", line):
                        vlan.varp_ips.append(IPNetwork(regex[0]))
                    if regex.match(" *load-interval (.*)", line):
                        vlan.load_interval = int(regex[0])
                    if regex.match(" *no mpls ip", line):
                        vlan.mpls_ip = False 
开发者ID:internap,项目名称:netman,代码行数:21,代码来源:arista.py

示例9: validate_dns

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def validate_dns(dns_list):
    """Validate a string is a single dns address or comma separated dns list

    :param dns_list: dns_list to be validated
    :returns: original dns_list.
    :raise: InvalidDNS if dns format is invalid

    """
    dns_nameservers = dns_list.split(',')
    try:
        for dns in dns_nameservers:
            netaddr.IPAddress(dns.strip(), version=4, flags=netaddr.INET_PTON)
    except netaddr.AddrFormatError:
        raise exception.InvalidDNS(dns=dns_list)
    else:
        return dns_list 
开发者ID:openstack,项目名称:magnum,代码行数:18,代码来源:utils.py

示例10: fallback_ip

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def fallback_ip(self):
        if self._values['fallback_ip'] is None:
            return None
        if self._values['fallback_ip'] == 'any':
            return 'any'
        try:
            address = IPAddress(self._values['fallback_ip'])
            if address.version == 4:
                return str(address.ip)
            elif address.version == 6:
                return str(address.ip)
            return None
        except AddrFormatError:
            raise F5ModuleError(
                'The provided fallback address is not a valid IPv4 address'
            ) 
开发者ID:mcgonagle,项目名称:ansible_f5,代码行数:18,代码来源:bigip_gtm_pool.py

示例11: fallback_ip

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def fallback_ip(self):
        if self._values['fallback_ip'] is None:
            return None
        if self._values['fallback_ip'] == 'any':
            return 'any'
        if self._values['fallback_ip'] == 'any6':
            return 'any6'
        try:
            address = IPAddress(self._values['fallback_ip'])
            if address.version == 4:
                return str(address.ip)
            elif address.version == 6:
                return str(address.ip)
            return None
        except AddrFormatError:
            raise F5ModuleError(
                'The provided fallback address is not a valid IPv4 address'
            ) 
开发者ID:mcgonagle,项目名称:ansible_f5,代码行数:20,代码来源:bigip_gtm_pool.py

示例12: address

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def address(self, value):
        pattern = '^(?P<ip>[0-9A-Fa-f:.]+)%?(?P<rd>\d+)?\/(?P<nm>\d+)$'
        matches = re.match(pattern, value)
        if not matches:
            raise F5ModuleError(
                "The specified address is malformed. Please see documentation."
            )
        try:
            ip = matches.group('ip')
            self._values['ip'] = str(IPAddress(ip))
        except AddrFormatError:
            raise F5ModuleError(
                'The provided address is not a valid IP address'
            )
        self._values['route_domain'] = matches.group('rd')
        self._values['netmask'] = matches.group('nm') 
开发者ID:mcgonagle,项目名称:ansible_f5,代码行数:18,代码来源:bigip_selfip.py

示例13: route_domain

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def route_domain(self):
        if self.want.route_domain is None:
            return None
        try:
            address = IPNetwork(self.have.ip)

            if self.want.netmask is not None:
                nipnet = "{0}%{1}/{2}".format(address.ip, self.want.route_domain, self.want.netmask)
                cipnet = "{0}%{1}/{2}".format(address.ip, self.have.route_domain, self.want.netmask)
            elif self.have.netmask is not None:
                nipnet = "{0}%{1}/{2}".format(address.ip, self.want.route_domain, self.have.netmask)
                cipnet = "{0}%{1}/{2}".format(address.ip, self.have.route_domain, self.have.netmask)

            if nipnet != cipnet:
                return nipnet
        except AddrFormatError:
            raise F5ModuleError(
                'The provided address/netmask value was invalid'
            ) 
开发者ID:mcgonagle,项目名称:ansible_f5,代码行数:21,代码来源:bigip_selfip.py

示例14: run

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def run(self, context):
        existing = self._existing_ips()
        try:
            ip_addresses = self._ip_address_list()
        except netaddr.AddrFormatError as exc:
            LOG.error("Cannot parse network address: %s", exc)
            return actions.Result(
                error="%s: %s" % (type(exc).__name__, str(exc))
            )

        result = []
        # NOTE(dtantsur): we iterate over IP addresses last to avoid
        # spamming the same BMC with too many requests in a row.
        for username, password in self.credentials:
            for port in self.ports:
                port = int(port)
                for ip in ip_addresses:
                    if (ip, port) in existing or (ip, None) in existing:
                        LOG.info('Skipping existing node %s:%s', ip, port)
                        continue

                    result.append({'ip': ip, 'username': username,
                                   'password': password, 'port': port})

        return result 
开发者ID:openstack,项目名称:tripleo-common,代码行数:27,代码来源:baremetal.py

示例15: ip_set_from_address_range

# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import AddrFormatError [as 别名]
def ip_set_from_address_range(start, end):
    try:
        start_ip_address = ip_address_from_address(start)
        end_ip_address = ip_address_from_address(end)
    except (NotSupported, ValueError) as e:
        raise ValueError(
            ('invalid IP range: %(start)s-%(end)s (%(message)s)') %
            {
                'start': start,
                'end': end,
                'message': e.message})
    except netaddr.AddrFormatError as e:
        raise ValueError(
            ("invalid IP range: '%(start)s-%(end)s' (%(message)s)") %
            {
                'start': start,
                'end': end,
                'message': e.message})

    if start_ip_address > end_ip_address:
        raise ValueError(
            ('invalid IP range: %(start)s-%(end)s (lower bound IP greater than'
             ' upper bound)') %
            {
                'start': start,
                'end': end})

    ip_range = netaddr.IPRange(start_ip_address, end_ip_address)

    return netaddr.IPSet(ip_range) 
开发者ID:dsp-jetpack,项目名称:JetPack,代码行数:32,代码来源:discover_nodes.py


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