Python 3 Socket Programming to Find IP Address of Website Domain in Terminal
611 views
Jun 3, 2025
Get the full source code of application here:
View Video Transcript
0:00
uh hello guys uh welcome to this video
0:02
So in this video I will show you a
0:04
Python script which will actually show
0:06
you the actual IP address of a specific
0:10
domain name So it's
0:13
a socket programming I will show you the
0:17
simplest of example of creating a socket
0:20
and finding out the IP address of the
0:26
domain name that you will enter Let me
0:28
show you example that I'm talking about
0:30
So we have written this simple Python
0:32
script using the socket
0:35
module inside Python So right here we
0:39
are importing this uh website
0:42
freemediatools.com
0:44
www.freemediatools.com So here you can
0:46
replace any website This is my website
0:49
here I want to find out the IP address
0:52
So as soon as I execute this Python
0:54
script now it will create the socket it
0:57
will make the request and then it will
1:00
find out the IP address which is there
1:03
You can see it socket successfully
1:05
created and then it prints out this is
1:08
actually the IP address of this domain
1:12
name The socket has been successfully
1:14
connected to Google So this
1:20
is so in this easy way you can replace
1:23
it here Let's suppose I replace it here
1:26
Google So now it will find out the IP
1:29
address of Google So you can
1:33
see So now let me show you the actual
1:35
module here Uh it's built in You need
1:38
not have to install it Simply import
1:41
this So it comes within the default
1:43
installation of Python So you simply
1:45
import the socket module and then you
1:49
actually import the system
1:52
module which is also a built-in module
1:54
And now inside the try block we simply
1:58
use the socket module It contains the
2:01
socket function And here you specify
2:04
these two arguments here which is socket
2:08
AF
2:18
in
2:24
N sock uh and then we need to say
2:30
stream after writing this uh the socket
2:33
will be successfully created
2:41
So in this way if
2:43
the socket will be successfully created
2:46
and then we will be making a simple
2:51
request So we'll set the port number The
2:54
port number will be 80 by default And
2:58
then inside again this try
3:03
block we will make this simple request
3:06
to find out the IP address of the
3:08
specific domain name So here it contains
3:10
this function which is get host by
3:15
name So here you need to specify the
3:18
address So you simply
3:21
say you replace
3:24
the website URL address You specify it
3:28
and then it makes the request and then
3:32
stores it inside this host IP variable
3:34
So you can simply print
3:37
it So if I run this now you will see
3:41
that
3:42
uh on line number
3:44
9
3:48
19 So this is parentheses
4:00
So now you can see it is printed out
4:03
successfully the IP
4:07
address If I change this let's suppose
4:11
to any
4:12
other So in this easy way you can find
4:15
out the IP address of any domain Just
4:18
write this and it will print out the IP
4:20
address You can change to any domain
4:23
here Let's suppose I change it to
4:25
github.com So again it will print out
4:27
the IP address So this is a very simple
4:31
example of socket programming inside
4:34
Python It's a very simple example of
4:37
finding out the IP address of a specific
4:40
domain It has various other uses as well
4:43
but this was the very simplest of
4:45
example So thank you very much for
4:48
watching this video and also check out
4:50
my website freemediatools.com
4:54
uh which contains thousands of tools
#Programming
#Scripting Languages