OBTAINING NETWORKING INFORMATION

The socket module is also responsible for talking with the host operating system to determine information such as the protocol and service lists and for communicating with the host domain name resolver to resolve hostnames into their IP addresses.

The information returned by most of the Python equivalent matches the information returned by the Perl functions when called in scalar context. However, all IP addresses are returned in the form of a string on dotted-quads, rather than the packed format returned by Perl.

Table 12.3. Perl and Python network information functions
Perl function Python equivalent
gethostbyname(hostname) (scalar context) gethostbyname(hostname)
gethostbyname (hostname) (list context) gethostbyname_ex(hostname) ...

Get Perl To Python Migration now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.