Answers for "Python program for getting url, hostname, port numbers"

0

Python program for getting url, hostname, port numbers

import socket
## getting the hostname by socket.gethostname() method
hostname = socket.gethostname()
## getting the IP address using socket.gethostbyname() method
ip_address = socket.gethostbyname(hostname)
## printing the hostname and ip_address
print(f"Hostname: {hostname}")
print(f"IP Address: {ip_address}")
Posted by: Guest on February-07-2022

Code answers related to "Python program for getting url, hostname, port numbers"

Python Answers by Framework

Browse Popular Code Answers by Language