Find a sequence of addresses.

    Args:
        addresses: a list of IPv4 or IPv6 addresses.

    Returns:
        A tuple containing the first and last IP addresses in the sequence,
        and the index of the last IP address in the sequence.
779796
def _find_address_range(addresses):
    
    first = last = addresses[0]
    last_index = 0
    for ip in addresses[1:]:
        if ip._ip == last._ip + 1:
            last = ip
            last_index += 1
        else:
            break
    return (first, last, last_index)
1265062
public static Set<String> getLocalAddresses() {
        try {
            List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());

            Set<String> result = new HashSet<>();

            for (NetworkInterface networkInterface : interfaces) {
                if (networkInterface.isLoopback() || !networkInterface.isUp())
                    continue;

                for (InterfaceAddress address : networkInterface.getInterfaceAddresses()) {
                    String addr = address.getAddress().getHostAddress();

                    if (addr == null || addr.isEmpty() || addr.contains(":"))
                        continue;

                    result.add(addr);
                }
            }

            return result;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
463940
def getIPaddresses(self):
        """"""
        if not self.ipAddress:
            self.ipAddress = ipAddresses.getAll() # update with IP address
        return self.ipAddress
74920
public ArrayList<InetAddress> getLocalAddresses()
  {
    synchronized (_addressCache) {
      ArrayList<InetAddress> localAddresses = _addressCache.get("addresses");
      
      if (localAddresses == null) {
        localAddresses = new ArrayList<InetAddress>();
        
        try {
          for (NetworkInterfaceBase iface : getNetworkInterfaces()) {
            for (InetAddress addr : iface.getInetAddresses()) {
              localAddresses.add(addr);
            }
          }
          
          Collections.sort(localAddresses, new LocalIpCompare());
          
          _addressCache.put("addresses", localAddresses);
        } catch (Exception e) {
          log.log(Level.WARNING, e.toString(), e);
        } finally {
          _addressCache.put("addresses", localAddresses);
        }
      }
      
      return new ArrayList<>(localAddresses);
    }
  }
54224
def _get_address_family(table):
        
        address_family_mapping = {
            'inet': 'ipv4',
            'inet6': 'ipv6',
            'inetflow': 'flow'
        }
        family = table.split('.')[-2]
        try:
            address_family = address_family_mapping[family]
        except KeyError:
            address_family = family
        return address_family
96425
def ip(ip_addr, return_tuple=True):
    
    regex_ip = __re.compile("^((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))$")
    if return_tuple:
        while not regex_ip.match(ip_addr):
            print("Not a good IP.")
            print("Please try again.")
            ip_addr = input("Please enter a IP address in the following format x.x.x.x: ")
        return ip_addr
    elif not return_tuple:
        if not regex_ip.match(ip_addr):
            return False
        else:
            return True
379209
def get_ip_addresses():
    
    log = logging.getLogger(mod_logger + '.get_ip_addresses')

    command = ['/sbin/ifconfig']
    try:
        result = run_command(command)
    except CommandError:
        raise
    ifconfig = result['output'].strip()

    # Scan the ifconfig output for IPv4 addresses
    devices = {}
    parts = ifconfig.split()
    device = None
    for part in parts:

        if device is None:
            if 'eth' in part or 'eno' in part:
                device = part
        else:
            test = part.split(':', 1)
            if len(test) == 2:
                if test[0] == 'addr':
                    ip_address = test[1]
                    log.info('Found IP address %s on device %s', ip_address,
                             device)
                    devices[device] = ip_address
                    device = None
    return devices
1353855
public static InetSocketAddress[] parseAddressList(String[] addresses) {
        InetSocketAddress[] isa = new InetSocketAddress[addresses.length];
        for (int x = 0; x < addresses.length; x++) {
            isa[x] = createInetSocketAddress(addresses[x]);
        }
        return isa;
    }
151190
public static int
    familyOf(InetAddress address) {
        if (address instanceof Inet4Address)
            return IPv4;
        if (address instanceof Inet6Address)
            return IPv6;
        throw new IllegalArgumentException("unknown address family");
    }
273119
def nextfreeip(self):
        
        allocated_ips = [ipaddress.ip_address(host['ip']) for host in self.hosts]
        for ip in self.netaddr:
            if str(ip).split('.')[-1] == '0':
                continue
            if ip not in allocated_ips:
                return ip
448872
def ip_address(self):
        
        networks = self.get("networks", {})
        v4nets = networks.get("v4", [])
        v6nets = networks.get("v6", [])
        try:
            return (v4nets + v6nets)[0].ip_address
        except IndexError:
            return None
799300
def _find_ip4_broadcast_addresses():
    
    yield "255.255.255.255"
    for interface in netifaces.interfaces():
        ifaddresses = netifaces.ifaddresses(interface)
        for family in ifaddresses:
            if family == netifaces.AF_INET:
                address_info = ifaddresses[family]
                for info in address_info:
                    if "broadcast" in info:
                        yield info['broadcast']
1253320
def lookup_ips (ips):
    
    hosts = set()
    for ip in ips:
        try:
            hosts.add(socket.gethostbyaddr(ip)[0])
        except socket.error:
            hosts.add(ip)
    return hosts
1356613
def addresses(self):
        
        import ns1.rest.ipam
        return ns1.rest.ipam.Addresses(self.config)
1103584
def ip_address_list(ips):
    
    # first, try it as a single IP address
    try:
        return ip_address(ips)
    except ValueError:
        pass
    # then, consider it as an ipaddress.IPv[4|6]Network instance and expand it
    return list(ipaddress.ip_network(u(ips)).hosts())
482951
def reset(self, addresses):
        
        request = self._call(SetEnqueueResetReverseDns.SetEnqueueResetReverseDns, IPs=addresses)
        response = request.commit()
        return response['Success']
189582
def get_sequence(self):
        
        if not self.address:
            raise StellarAddressInvalidError('No address provided.')

        address = self.horizon.account(self.address)
        return int(address.get('sequence'))