In this tutorial, we will be looking at how to get the IP address of a certain domain using python.
Now let’s create a python and import the socket module as shown below. You don’t need to install socket since it comes with batteries in python
import socket
Now let’s create a function to get the IP address.
def server_info():
server = "www.google.com"
try:
print("Ip address : ", socket.gethostbyname(server))
except socket.error as err:
print(f"{server} : {err}")
Now let’s check if our code is being run as a script as shown below.
if __name__ == "__main__":
server_info()
Now let’s run our application and here is our Ip address shown below.
There you have it, Thanks for reading. Happy Coding.