Python Socket How To Get Website IP Address

Python Socket How To Get Website IP Address – Sometimes, you need to translate a machine’s hostname into its corresponding IP Address, for example, a quick domain name lookup. This article introduces a simple function to do that. If you need to know the IP Address of a Website, you can use a built-in library function, gethostbyname(). In this case, you need to pass the remote hostname as its parameter.

 

 

Also you can check Python Socket Programming Articles

1: Python Socket Programming How To Create Socket

2: Python Socket How To Get Local Machine IP Address

 

 

 

 

So now this is the complete code for this article

 

 

 

 

How it Works

first of all we need to import socket library , after that we have  wraped the gethostbyname() method inside a  function called main(). In this article, we introduced the notion of exception handling. As you can see, we wrapped the main function call inside a try-except block. This means that if some error occurs during the execution of this function, this error will be  dealt with by this try-except block.

 

 

 

Now run the complete code and this will be the result

Python Socket How To Get Website IP Address
Python Socket How To Get Website IP Address

 

 

 

 

 

Also you can watch the complete video for this article

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×