Ben Chuanlong Du's Blog

It is never too late to learn.

Hands on the Socket Module in Python

In [1]:
import socket
In [3]:
hostname = socket.gethostname()
In [4]:
socket.gethostbyname(hostname)
Out[4]:
'172.17.0.3'
In [7]:
[m for m in dir(socket) if "host" in m]
Out[7]:
['gethostbyaddr',
 'gethostbyname',
 'gethostbyname_ex',
 'gethostname',
 'sethostname']
In [ ]:

Comments