|
|
|
|
|
|
|
|
|
|
|
#!/usr/bin/env python |
|
|
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
|
|
|
|
|
|
|
import socket |
|
|
|
|
|
|
|
|
|
|
|
def get_hostname(host_or_ip): |
|
|
|
|
|
host_or_ip = socket.getfqdn(host_or_ip) |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
return socket.gethostbyaddr(host_or_ip)[0] |
|
|
|
|
|
except socket.gaierror: |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def get_aliases(host_or_ip): |
|
|
|
|
|
host_or_ip = socket.getfqdn(host_or_ip) |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
return socket.gethostbyaddr(host_or_ip)[1] |
|
|
|
|
|
except socket.gaierror: |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def get_ip_addrs(host_or_ip): |
|
|
|
|
|
host_or_ip = socket.getfqdn(host_or_ip) |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
return socket.gethostbyaddr(host_or_ip)[2] |
|
|
|
|
|
except socket.gaierror: |
|
|
|
|
|
return False |