Resolving the IP address with the socket package

If you would like to see the local machine IP, you can do so using the ifconfig command in Linux and the ipconfig command in Windows. Here, we'll do this in Python using the built-in function:

>>> import socket
>>> socket.gethostbyname('python.org')
'10.0.2.15'

This process is known as a host file-based name resolution. You can send a query to a DNS server and ask for the IP address of a specific host. If the name has been registered properly, you will get a response from the server.

Here are some useful methods for gathering this kind of information: