How to show hostname & IP address with python programming

The Internet Protocol assigns a 4-byte address to every computer connected to the network. Such
addresses are usually written as four decimal numbers, separated by periods, which each represent a
single byte of the address. Each number can therefore range from 0 to 255. So an IP address looks like

Because purely numeric addresses can be difficult for humans to remember, the actual people using
the Internet are generally shown hostnames rather than IP addresses. The user can simply type and forget that behind the scene this resolves to an address like, to which
their computer can actually address packets for transmission over the Internet.

import socket
hostname = ‘’
IPaddress = socket.gethostbyname(hostname)
print ‘The address of’, hostname, ‘is’, IPaddress