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
this:
202.168.3.180

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
google.com and forget that behind the scene this resolves to an address like 74.125.67.103, to which
their computer can actually address packets for transmission over the Internet.

#!/usr/bin/python
import socket
hostname = ‘maps.google.com’
IPaddress = socket.gethostbyname(hostname)
print ‘The address of’, hostname, ‘is’, IPaddress

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *