Get list of ipv4 addresses for hostname
769521
def get_ipv4(hostname):
    
    addrinfo = socket.getaddrinfo(hostname, None, socket.AF_INET,
                                  socket.SOCK_STREAM)
    return [addrinfo[x][4][0] for x in range(len(addrinfo))]
654409
def fake_getaddrinfo(
        host, port, family=None, socktype=None, proto=None, flags=None):
    """"""
    return [(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP,
             '', (host, port))]
450090
def getaddresses (addr):
    """"""
    parsed = [mail for name, mail in AddressList(addr).addresslist if mail]
    if parsed:
        addresses = parsed
    elif addr:
        # we could not parse any mail addresses, so try with the raw string
        addresses = [addr]
    else:
        addresses = []
    return addresses
1299687
def _get_distinct_hostnames(self):
        
        hostnames = []
        for section in self.sections:
            hostnames.extend(self._group_get_hostnames(section['name']))
        return set(hostnames)
516825
def ResolveHostnameToIP(host, port):
  """"""
  ip_addrs = socket.getaddrinfo(host, port, socket.AF_UNSPEC, 0,
                                socket.IPPROTO_TCP)
  # getaddrinfo returns tuples (family, socktype, proto, canonname, sockaddr).
  # We are interested in sockaddr which is in turn a tuple
  # (address, port) for IPv4 or (address, port, flow info, scope id)
  # for IPv6. In both cases, we want the first element, the address.
  result = ip_addrs[0][4][0]
  # TODO: In Python 2, this value is a byte string instead of UTF-8
  # string. To ensure type correctness until support for Python 2 is dropped,
  # we always decode this value.
  if compatibility.PY2:
    result = result.decode("ascii")
  return result
8341
def ip_to_host(ip):
    '''
    
    '''
    try:
        hostname, aliaslist, ipaddrlist = socket.gethostbyaddr(ip)
    except Exception as exc:
        log.debug('salt.utils.network.ip_to_host(%r) failed: %s', ip, exc)
        hostname = None
    return hostname
1199039
private List<String> getHttpAddresses() {
    
    String[] hosts = JournalConfigHelper.getJournalHttpHosts(conf);
    String pref = "http://";
    
    for (int i = 0; i < hosts.length; i++) {
      hosts[i] = pref + hosts[i];
    }    
    return Arrays.asList(hosts);
  }
765758
def get_by_hostname(self, hostname):
        
        resources = self._client.get_all()

        resources_filtered = [x for x in resources if x['hostname'] == hostname]

        if resources_filtered:
            return resources_filtered[0]
        else:
            return None
442361
def network_hosts(value, options=None, version=None):
    '''
    
    '''
    ipaddr_filter_out = _filter_ipaddr(value, options=options, version=version)
    if not ipaddr_filter_out:
        return
    if not isinstance(value, (list, tuple, types.GeneratorType)):
        return _network_hosts(ipaddr_filter_out[0])
    return [
        _network_hosts(ip_a)
        for ip_a in ipaddr_filter_out
    ]
463626
def _list_hosts():
    '''
    
    '''
    try:
        return __context__['hosts._list_hosts']
    except KeyError:
        count = 0
        hfn = __get_hosts_filename()
        ret = odict.OrderedDict()
        try:
            with salt.utils.files.fopen(hfn) as ifile:
                for line in ifile:
                    line = salt.utils.stringutils.to_unicode(line).strip()
                    if not line:
                        continue
                    if line.startswith('#'):
                        ret.setdefault('comment-{0}'.format(count), []).append(line)
                        count += 1
                        continue
                    if '#' in line:
                        line = line[:line.index('#')].strip()
                    comps = line.split()
                    ip = comps.pop(0)
                    ret.setdefault(ip, []).extend(comps)
        except (IOError, OSError) as exc:
            salt.utils.files.process_read_exception(exc, hfn, ignore=errno.ENOENT)
            # Don't set __context__ since we weren't able to read from the
            # hosts file.
            return ret

        __context__['hosts._list_hosts'] = ret
        return ret
1155908
def get_ip_address(domain):
    
    if "://" not in domain:
        domain = "http://" + domain

    hostname = urlparse(domain).netloc

    if not hostname:
        raise ValueError("Can't parse hostname!")

    return socket.gethostbyname(hostname)
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
9627
function(hostname, callback) {
  get_nodes(function(err,nodes) {
    if (err) return callback(err);

    var n = nodes.filter(function(node) {
      return node.name === hostname;
    });

    callback(null,(n.length === 1) ? n[0].ip_address : null);
  });
}
882452
def parse_hostname(cls, hostname):
        ''''''
        if hostname.startswith('['):
            return cls.parse_ipv6_hostname(hostname)
        else:
            try:
                new_hostname = normalize_ipv4_address(hostname)
            except ValueError:
                # _logger.debug('', exc_info=True)
                new_hostname = hostname

            new_hostname = normalize_hostname(new_hostname)

            if any(char in new_hostname for char in FORBIDDEN_HOSTNAME_CHARS):
                raise ValueError('Invalid hostname: {}'
                                 .format(ascii(hostname)))

            return new_hostname
564858
def getHostsFromPBS():
    """"""
    # See above comment about Counter
    with open(os.environ["PBS_NODEFILE"], 'r') as hosts:
        hostlist = groupTogether(hosts.read().split())
        retVal = []
        for key, group in groupby(hostlist):
            retVal.append((key, len(list(group))))
        return retVal
1008744
def _get_hosts_from_names(self, names):
        
        result = set()
        hosts = map(lambda x: x.strip(), names.split(','))
        for h in hosts:
            if valid_hostname(h.split(':')[0]):
                result.add(h if ':' in h else '%s:%d' % (h, self.PORT))
            else:
                raise conferr('Invalid hostname: %s' % h.split(':')[0])
        return list(result)
453675
def get_ip4():
    
    addresses = []

    shell_cmd = "ifconfig | awk '/inet addr/{print substr($2,6)}'"
    proc = subprocess.Popen([shell_cmd], stdout=subprocess.PIPE, shell=True)
    (out, err) = proc.communicate()
    ip_addresses = out.split('\n')
    for addr in ip_addresses:
        if re.match(r'\d{1,4}\.\d{1,4}\.\d{1,4}\.\d{1,4}', addr):
             addresses.append(addr)
    return addresses