पायथन gethostname (), gethostbyname () दो फ़ंक्शन प्रदान करता है। gethostname() स्थानीय मशीन के लिए मानक होस्ट नाम को पुनः प्राप्त करता है। gethostbyname() होस्ट डेटाबेस से होस्ट नाम से संबंधित होस्ट जानकारी को पुनः प्राप्त करता है।
Socket. gethostname() Socket. gethostbyname()
एल्गोरिदम
Step 1: use module socket. Step 2: use gethostname() retrives the standard host name for the local machine. Step 3: use gethostbyname() retrives host information corresponding to a host name from a host database.
उदाहरण कोड
# Display hostname andIP address
import socket
def host_IP():
try:
hname = socket.gethostname()
hip = socket.gethostbyname(hname)
print("Hostname: ",hname)
print("IP Address: ",hip)
except:
print("Unable to get Hostname and IP")
# Driver code
host_IP() #Function call
आउटपुट
Hostname: Satyajit-PC IP Address: 192.168.1.66