Patched 'getaddrinfo' with default family IPv4 (enabled by settings IPV4_ONLY=True)
766016
def getaddrinfo_wrapper(host, port, family=socket.AF_INET, socktype=0, proto=0, flags=0):
    """"""
    return orig_getaddrinfo(host, port, family, socktype, proto, flags)
15047
def default_gw_ipaddr
      ip = case `/bin/uname -s`.rstrip
           when 'Linux'
             `/sbin/ip route get 8.8.8.8`.split("\n")[0].split.last
           when 'SunOS'
             `/sbin/ifconfig $(/usr/sbin/route -n get 1.1.1.1  | awk '$1 == "interface:" {print $2}') | awk '$1 == "inet" { print $2 }'`
           else
             raise "Unsupported platform to detect gateway IP address: #{`/bin/uname`}"
           end
      ip = ip.rstrip
      raise "Failed to run command lines or empty result" if ip == '' || $?.exitstatus != 0
      ip
    end
1053592
def getAddr (self, ifname):
        
        if sys.platform == 'darwin':
            return ifconfig_inet(ifname).get('address')
        return self._getaddr(ifname, self.SIOCGIFADDR)
848555
def _find_ip4_addresses():
    
    global _ip4_addresses
    proto = socket.AF_INET
    if _ip4_addresses is None:
        _ip4_addresses = []

        #
        # Determine the interface for the default gateway
        # (if any) and, later, prioritise the INET address on
        # that interface.
        #
        default_gateway = netifaces.gateways()['default']
        if proto in default_gateway:
            _, default_gateway_interface = default_gateway[proto]
        else:
            default_gateway_interface = None

        for interface in netifaces.interfaces():
            for info in netifaces.ifaddresses(interface).get(netifaces.AF_INET, []):
                if info['addr']:
                    if interface == default_gateway_interface:
                        _ip4_addresses.insert(0, info['addr'])
                    else:
                        _ip4_addresses.append(info['addr'])

    return _ip4_addresses
1209336
function getAddress(loopback, opt_family) {
  var family = opt_family || 'IPv4';
  var addresses = [];

  var interfaces;
  if (loopback) {
    var lo = getLoInterface();
    interfaces = lo ? [lo] : null;
  }
  interfaces = interfaces || os.networkInterfaces();
  for (var key in interfaces) {
    interfaces[key].forEach(function(ipAddress) {
      if (ipAddress.family === family &&
          ipAddress.internal === loopback) {
        addresses.push(ipAddress.address);
      }
    });
  }
  return addresses[0];
}
304339
def resolve_network_cidr(ip_address):
    '''
    
    '''
    netmask = get_netmask_for_address(ip_address)
    return str(netaddr.IPNetwork("%s/%s" % (ip_address, netmask)).cidr)
464241
def _detect(self):
        """"""
        theip = None
        try:
            if self.opts_family == AF_INET6:
                addrlist = netifaces.ifaddresses(self.opts_iface)[netifaces.AF_INET6]
            else:
                addrlist = netifaces.ifaddresses(self.opts_iface)[netifaces.AF_INET]
        except ValueError as exc:
            LOG.error("netifaces choked while trying to get network interface"
                      " information for interface '%s'", self.opts_iface,
                      exc_info=exc)
        else:  # now we have a list of addresses as returned by netifaces
            for pair in addrlist:
                try:
                    detip = ipaddress(pair["addr"])
                except (TypeError, ValueError) as exc:
                    LOG.debug("Found invalid IP '%s' on interface '%s'!?",
                              pair["addr"], self.opts_iface, exc_info=exc)
                    continue
                if self.netmask is not None:
                    if detip in self.netmask:
                        theip = pair["addr"]
                    else:
                        continue
                else:
                    theip = pair["addr"]
                break  # we use the first IP found
        # theip can still be None at this point!
        self.set_current_value(theip)
        return theip
88175
def cli(env, ip_version):
    """"""

    mgr = SoftLayer.NetworkManager(env.client)

    table = formatting.Table(['id', 'ip', 'assigned', 'target'])

    version = None
    if ip_version == 'v4':
        version = 4
    elif ip_version == 'v6':
        version = 6

    ips = mgr.list_global_ips(version=version)

    for ip_address in ips:
        assigned = 'No'
        target = 'None'
        if ip_address.get('destinationIpAddress'):
            dest = ip_address['destinationIpAddress']
            assigned = 'Yes'
            target = dest['ipAddress']
            virtual_guest = dest.get('virtualGuest')
            if virtual_guest:
                target += (' (%s)'
                           % virtual_guest['fullyQualifiedDomainName'])
            elif ip_address['destinationIpAddress'].get('hardware'):
                target += (' (%s)'
                           % dest['hardware']['fullyQualifiedDomainName'])

        table.add_row([ip_address['id'],
                       ip_address['ipAddress']['ipAddress'],
                       assigned,
                       target])
    env.fout(table)
454974
def get_host_advanced(name=None, ipv4addr=None, mac=None, **api_opts):
    '''
    
    '''
    infoblox = _get_infoblox(**api_opts)
    host = infoblox.get_host_advanced(name=name, mac=mac, ipv4addr=ipv4addr)
    return host
729733
def inet_ntop(af, addr):
    """"""
    # Use inet_ntop if available
    addr = bytes_encode(addr)
    try:
        return socket.inet_ntop(af, addr)
    except AttributeError:
        try:
            return _INET_NTOP[af](addr)
        except KeyError:
            raise ValueError("unknown address family %d" % af)
781981
def _get_ipv4_from_binary(self, bin_addr):
        """"""

        return socket.inet_ntop(socket.AF_INET, struct.pack("!L", bin_addr))
718029
def _resolve_addrs(straddrs, port, ignore_unavailable=False, protocols=[socket.AF_INET, socket.AF_INET6]):
    

    res = []
    for sa in straddrs:
        try:
            ais = socket.getaddrinfo(sa, port)
            for ai in ais:
                if ai[0] in protocols:
                    res.append((ai[0], ai[4], ai[0], ai[4][0]))
                    break
            else:
                # Try to convert from IPv4 to IPv6
                ai = ais[0]
                if ai[0] == socket.AF_INET and socket.AF_INET6 in protocols:
                    to = socket.getaddrinfo('::ffff:' + ai[4][0], port, socket.AF_INET6)[0][4]
                    res.append((socket.AF_INET6, to, ai[0], ai[4][0]))
        except socket.gaierror:
            if not ignore_unavailable:
                raise

    return res
777145
def gateways_info():
    
    data = netifaces.gateways()
    results = {'default': {}}

    with suppress(KeyError):
        results['ipv4'] = data[netifaces.AF_INET]
        results['default']['ipv4'] = data['default'][netifaces.AF_INET]
    with suppress(KeyError):
        results['ipv6'] = data[netifaces.AF_INET6]
        results['default']['ipv6'] = data['default'][netifaces.AF_INET6]

    return results
1162306
def _set_static_ip(name, session, vm_):
    '''
    
    '''
    ipv4_cidr = ''
    ipv4_gw = ''
    if 'ipv4_gw' in vm_.keys():
        log.debug('ipv4_gw is found in keys')
        ipv4_gw = vm_['ipv4_gw']
    if 'ipv4_cidr' in vm_.keys():
        log.debug('ipv4_cidr is found in keys')
        ipv4_cidr = vm_['ipv4_cidr']
        log.debug('attempting to set IP in instance')
        set_vm_ip(name, ipv4_cidr, ipv4_gw, session, None)
560739
def set_ipv4(self, ip):
        
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        bin_ip = socket.inet_aton(ip)
        ifreq = struct.pack('16sH2s4s8s', self.name, socket.AF_INET, '\x00'*2, bin_ip, '\x00'*8)
        fcntl.ioctl(sock, self.SIOCSIFADDR, ifreq)
        ifreq = struct.pack('16sH', self.name, self.IFF_UP|self.IFF_POINTOPOINT|self.IFF_RUNNING|self.IFF_MULTICAST)
        fcntl.ioctl(sock, self.SIOCSIFFLAGS, ifreq)
783044
def first_ipv6(self) -> Optional[AddressInfo]:
        ''''''
        for info in self._address_infos:
            if info.family == socket.AF_INET6:
                return info
1362935
def _get_ipv6addrs(self):
        
        addrs = self._get_addrs()
        ipv6addrs = addrs.get(netifaces.AF_INET6)
        if not ipv6addrs:
            return {}
        return ipv6addrs[0]