Skip to content

Instantly share code, notes, and snippets.

@alex21289
Last active Mar 8, 2020
Embed
What would you like to do?
Network/Python
import socket
def main():
def get_IP():
try:
host_name = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
host_fqdn = socket.getfqdn()
return host_name, host_fqdn, host_ip
except:
print("Unable to get Hostname and IP")
host = get_IP()
print("Host: "+host[0])
print("FQDN: "+host[1])
print("IP: "+host[2])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment