Port scanning would sockets.
Hi, guys.
And welcome back to the course.
I must tell you that sometimes you are going to be using so many ports that you actually want to be
able to see which port is connected and which port is not connected.
And for that reason, you want to check the connection on each port and if it's actually connected to
certain server.
Right.
So for that reason, I'm going to show you a very simple script with which you can check that.
And let's create here a new Python file.
And this will be called Scan Port.
OK.
And the court has heard a few lies, but it's actually quite useful and they always use it in order
to check my connections.
So let me first do the usual stuff.
Yuzu been in V.
And then item.
Three.
OK, and let me enable the syntax, so let's import circuit and let's do IP address will be equal to
input.
And here we are going to type our IP address.
So let's write enter IP.
Address for port.
Scanning.
OK, so here you enter an IP address and let's write or underscore.
In it to be equal to again in.
That's right, enter first sports, OK?
And after that, let's fight for it.
And and here I will do in sports and then.
And third, last fourth.
So we're going to check from the first last sport report if it has the right connection or not.
So obviously here we need to create a for loop for each sport.
And then we're right for sports in range.
And the range is going to be from the first to the last sport.
So I will do sport in it here supporting it and then the last sport in the range.
So Colma Integer and the last port in the range will be the port and OK and here will add one as well.
OK, so for each of the ports that remark will create a soc variable which will be equal to socket n
socket and then in the brackets.
A socket, a dot, a if I net and then socket that so extreme.
OK.
And after that I would also not sit by mouth in here we'll have five.
And then the results actually result will be equal to soak, dot connect actually to connect X for external.
And here I'll write IP address coma for OK.
And then if the result is equal to zero then we'll write Prince Port Colma.
Let's write open here so we can see the other so on and let's write so else.
OK or if the port is close to print here Port Como and then you see that the port is actually closed.
So I would close OK and then suck that close and we already here.
So let's not try to run the actual code and see if we can get the connection and if our port will be
running.
So let's write aways and here where is OK so ports can port to Python.
And then scan port in those you can see first who are asked for IP address, but the main source of
fans who are right about that.
What about that killed Army dot com?
Let's run it and here we will be checking the port.
So let's enter the ports from 80 to 85 and you can see that we got information very fast.
So you can see that now we have connection Port 80 and we have it with the server, Scutaro dot com
in the rest of the ports.
They are closed.
Let's do it again so you can see how it happens.
Let's go on our website.
Actually, that would allow that YouTube dot com and the first port will be, let's do it, 79 to 86.
And you can see that information takes way longer than us.
YouTube dot com, I guess, is slightly heavier.
But you can see that now.
Again, we get the information data.
So we're connecting to YouTube dot com.
And this is the way, guys, you can always check if you're connected to a certain website or if certain
port is busy.
And this was everything I want to share with you for today, for our connectivity and how you can scan
different ports.
Thanks for watching and I'll see you in the next video.