Useful socket methods

So far, you have gained knowledge of socket and client-server architecture. At this level, you can make a small program of networks. However, the aim of this book is to test the network and gather information. Python offers very beautiful as well as useful methods to gather information. First, import the socket and then use these methods:

  • socket.gethostbyname(hostname): This method converts a hostname to the IPv4 address format. The IPv4 address is returned in the form of a string. Here is an example:
       >>> import socket>>>          socket.gethostbyname('thapar.edu')'220.227.15.55'>>>>>>          socket.gethostbyname('google.com')'173.194.126.64'>>>

I know you are thinking about the nslookup command. Later, you will see more magic. ...

Get Python Penetration Testing Essentials 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.