OS: Windows 7
#!/usr/bin/env python3 # Python3 code to display hostname and # IP address # Importing socket library import socket # Function to display hostname and # IP address def get_Host_name_IP(): try: host_name = socket.gethostname() host_ip = socket.gethostbyname(host_name) print("Hostname : ",host_name) print("IP : ",host_ip) except: print("Unable to get Hostname and IP") # Driver code get_Host_name_IP() #Function call #This code is conributed by "Sharad_Bhardwaj"
原文地址:https://www.cnblogs.com/python-abc/p/11715146.html
时间: 2024-10-31 15:54:27