Every line of 'python get hostname' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
7 def hostname(): 8 """Get hostname.""" 9 return socket.gethostname()
38 def resolve_hostname(hostname): 39 return socket.gethostbyname(hostname)
23 def get_ip(): 24 try: 25 hostname = socket.getfqdn(socket.gethostname()) 26 ipaddr = socket.gethostbyname(hostname) 27 except Exception as msg: 28 print(msg) 29 ipaddr = '' 30 return ipaddr
102 def GetFQDN(): 103 return socket.getfqdn()
35 def query_remote_hostname(): 36 """ 37 Get the remote hostname 38 """ 39 import socket 40 return socket.gethostname()
46 def GetHostInfo(): 47 """Get information about the host.""" 48 hostname = GetFQDN() 49 if hostname in BAD_HOSTNAMES: 50 raise AssertionError('Hostname cannot be one of %s' % ','.join(BAD_HOSTNAMES)) 51 ipaddr = GetIP(hostname) 52 host_check, host_aliases, _ = socket.gethostbyaddr(ipaddr) 53 return hostname, ipaddr, host_aliases + [host_check]
125 def getHostName(): 126 ''' 127 Returns current host name 128 In fact, it's a wrapper for socket.gethostname() 129 ''' 130 hostname = socket.gethostname() 131 if 'win32' in sys.platform: 132 hostname = hostname.decode(sys_fs_enc) 133 134 hostname = six.text_type(hostname) 135 logger.info('Hostname: {}'.format(hostname)) 136 return hostname
44 def get_host_by_addr(self): 45 '''Return a triple (hostname, aliaslist, ipaddrlist) - https://docs.python.org/2/library/socket.html#socket.gethostbyaddr''' 46 try: 47 return socket.gethostbyaddr(str(self.ip)) 48 except Exception as e: 49 raise e
37 def get_host_by_name(self): 38 try: 39 return str(dns.resolver.query(self.names[0])[0]) 40 except Exception as e: 41 raise e
38 @property 39 def hostname(self): 40 with self.open(_NETFILE) as fhandler: 41 for line in fhandler.read().splitlines(): 42 attr, value = line.split('=') 43 if attr == 'HOSTNAME': 44 return value