Getting false information.
Hi, everyone.
Welcome back to the course today.
We're going to go straight to coding and for that reason, a terminal.
So here is our terminal.
Let's make it a bit bigger so you can see what I'm typing in here.
We're going to try some comments in order to see the force that we are going to be using in that course.
So the first thing I will do is I will go to python mode.
So Python here and now we're in python mode and I'll write import sockets, OK?
And usually I think everybody would have the socket package already installed.
But if you don't have it installed, you already know how to install packages just by pipe install and
the socket package anyways.
So now let's write a command that will basically show you the type of the socket we have.
As I said, the sockets are marked by fourth numbers.
So for example, if I write socket dot get.
Server by four and right port 80.
OK, let me fix my mistake.
Yes, it's get serve Bayport, right?
Yes.
So if I get served by Porth a team, you can see that on eight.
We have the HTP protocol or for example, if I write the same.
Socket not get served by.
Brought by port.
OK, get there by port, and if we're right or to end the trip, you can see that port when the trip
is telnet and then it is actually a function that enables you to connect to different machines that
are.
Attached to your current machine, but anyways, this is the way that you can actually see the different
types of products on the different parts, but let's actually create a script that will show you all
this instantly.
And for that reason, I open by charm.
So let's open the chart here.
So let's hit the resources folder here.
And of course, I will create a new folder, which will be called Section six.
But let's wait to load a bit.
So let's create in our resources folder a new directory, which is going to be called Section six.
OK, and now a Section six who are going to be able to create our new files, which are only going to
be related to sockets.
So.
Now, I will create the first file and in this file, guys, and this will be a -- and it will
check all the reports in their names.
So the name will be.
Show.
Ports, OK, and don't worry, even though just FYI, we want to show the ports later on in the course,
we'll create our own server and our own client and I will show you how they can exchange information
simultaneously.
So let's right here, user Bill Ian V Slash without slash Python three.
And then let's import sockets.
OK, and after that, I will write a simple function which will be called So Def Find, Serve, Serve.
Name or fanservice name, and this function will not take any argument.
So let's first create a variable which will be called Perreault Taco Name.
OK, and this will be equal to TCAP.
So this is a Tsipi protocol.
OK, and then I will write for 14.
The range of 80 and 25.
What we would like to do is to print for them percent is in here, you can do like that.
OK, this simpleton's.
Service.
Name.
OK, and then here again, percent is OK, and now the percent S's are going to be related to the following
things.
So here I our right board, OK, which is the name of the variable that we passed.
So it will be either 80 or twenty five and then socket dot.
Get serve.
By.
Bayport.
OK, get served by in here.
All right, Port, so it takes a number of the port and then.
Protocol name.
OK, so the protocol name here is the Tsipi, and the first name will be first 80 and then 25.
OK.
So we're done here, guys, and then I will create another statement, but this statement will be.
Actually, outside of the Falu, so.
Here, I will print, so I will print actually with Capital Port and then as.
And basically, we're going to do a similar thing here, so I write service.
Name.
OK.
And then I can present is.
And here, the percentages would be actually the first fifty three and then socket not.
You get several Bayport.
And then 53 and then you, DP, OK, and why we're doing this separately, this is because the participant
actually has two types.
Why would you report we're only going to support 53 here?
OK, this is the reason why would we just separately want within the for loop and the other one without.
So let's actually run this function.
So let's try the standard if name.
Equals Main, then find.
Service name.
OK, so this is the function that is going to be running.
And now let's save that and I will go back to here.
Let's exit.
So control.
OK, and I'll go to the folder that I have this file installed.
And when I write a wish, you can see the support file here.
So let's copy it and I'll write Python.
And let's face it.
And you can see that guys here, we're actually getting so caught 80 and we see the service name is
HTP and then we get the service name of twenty five that is SMPTE P and finally we're getting the service
name of the port.
Fifty three, which is our domain.
OK, so the domain is actually the UDP port or UDP type of the protocol.
So on the site you can also check on the port name of a web page.
And for that reason let's actually create another file and let's create new light on file in the name
of this file will be get.
Address.
OK, so let's right here, slash user slash being slash Ian Ian fee.
Python three and let's import socket.
OK, and what we're going to do here is simply to get a new form of a website.
So let's do a tri statement so we ensure that if we don't find the website, we will get the correct
error.
So I will do try and then here I'll write in full list will be equal to socket dot get server Bayport.
Actually let's do it differently and get others to follow.
And here in the ultrasound for first of all I read the website so this will be skewed.
R.M. dot com then double double w ok coma's zero then Cómo socket dot sockets stream.
OK, so, so this room will actually take the stream of data from the website.
The Zero.
And then let's try the circuit.
That's a.
Underscore article, then this right here, the socket, not a.
Underscore the so here is socket, I underscore V.
Four months and then another pipe and the pipes to actually separate the different information.
So this right here socket, not a.
Underscore can name calling and that to the guys here.
Now, let's right, except.
OK, so this is the exception, and they are right here, socket Dr. Gaier.
US e.
OK, so if we were still there, who would like to print here?
Name service.
Failure.
Then Colma idot args.
OK.
And then I will write one here and then.
That's right sis dot exit.
And we're just on one, that's it.
OK, so let's right now here info will be equal to Infl.
List and then zero.
OK, and then let's try to print in full list and actually here's capital letter, OK, awfullest,
that's it then.
Let's write sockets underscore our X will be equal to in full and zero to three.
OK, so this is our Socotra list and we have the input data from zero to three and.
As you can see, the parameter, because the data from the fullest ADIRU position and obviously here
we will hear from Matrixx on their position will have a certain amount of arguments which are on the
same line.
And we will see exactly them then.
And let's try and address the course info.
Four and then as will be equal to circuit.
That socket and here I will write the.
Star.
Circuit.
OK.
And then let's try to narrow exception that be a short one, so let's try to try as dots connect and
then here was the address and let's write exception or accept circuit adult error as E and here print
actually their message.
So I write network.
Failure.
OK.
And after that, this right dot ARC's.
One and then else.
So if we get any clearer who print or actually if we don't get there, all princesses.
Host Cuomo Info three.
OK, so the infantry is going to go to the horse and we're right is.
Is listening on board eight.
OK, let's say up in this, try to run the code now, first of all, as Right Airways and as you can
see here, you can see get out of this script.
So let's write Python and get the address.
And you can see that our code is running successfully, guys.
So you can see here that, first of all, the first very important thing to notice is that we have a
success.
So this is the last syntax that we just wrote here.
Let me make this more actually, so you can see success cost Scutari dot com, which is for Dautry is
listening Conforth eight, which is the port we actually opened to the server.
OK, this is our socket and you can see the data here that we get Alturas family dot A.F. in it, which
is the one we stated right here.
So we're getting there in it too.
Then we're getting the socket kind and the socket stream.
OK.
We get the name of the port, we get also the IP address and the port that is opened.
OK, so this is how you can actually connect to a website and see the port that is open to that website
and potentially do some controls on it.
But as you can see, you cannot only stick to opening servicing clients in your computer, but also
to accessing different websites located on the Web.
And I can also prove this in another way.
So if write item here and if we simply write import to socket and then if a right socket dot get caused
by.
Name.
OK, get hosed by name and then the right name of a website like Skilled Army dot com.
OK, you will see that you are immediately getting the IP address of the Scutari dot com.
Or let's try another website that you definitely use, YouTube dot com.
And you can see that you're getting the IP of the YouTube dot com, which is a hundred seventy two to
seventeen dot for dot forty six.
So this is a very easy way to get the IP addresses using sockets and connect to different web pages.
And if you actually want to get the full information for a website, you can actually do it within less
than ten lines of code and I will show you how it's done.
So let's create another Python file and here I will.
Kowit get.
Well, OK.
So you can see how easy it is actually to write a simple script and get the information off a website.
So if I write again, user slash, bean slash E and the V Python three and then you four import sockets,
you can then write a D get underscore remold info.
OK, and here if I write remote, underscore costs and let the remote holes be skilled rmv dot com and
I'll write.
I would, I would, I would not secure ami dot com and then let's do it as an exception so it's easier
for the computer, for the program to cope with our code.
So let's print here and I will show how you can immediately print here all the information you need
for the website.
If I write IP address of person s and then outside I will again write percent.
Percent, yes.
OK, so that could be done by writing two percent and the first percent will be the remote coast.
OK, the one that you stated earlier on.
So it will be Scutaro dot com and this is the host passing.
And then we can write circuits that get hostname and you can write inside Remote Coast.
OK, so we are getting here today, pylorus of the host, obviously, and this is how actually you can
write a script to get the IP address and all the information you need.
And now let's do.
Except for exception in the socket, that error was er a message for message.
OK, and let's right here print and let's right here the error message so percent is OK and 10 percent
is in on the placeholder percent.
I will just state the remote host's so remote host and then error message that will be passed.
OK, and finally let's just run the function.
So if name.
Equals Main.
OK, so if name equals Main, they would like to run the function, which is called to get the remote
info.
OK, let's say that by pressing the controllers in, I will also exit the python mode here and you should
be in your Section six folder in order to run the file.
So far, right away, as you can see that the gateway file was here, so.
Right, Python.
You get.
Web.
OK, for one of the guys you can see there are some mirrors, so let's go back to the court and just
address them.
And if I go back, I can actually see where there is because we need to right here get hosted by name,
but not get hostname.
OK, so I will delete of this.
Let's save it.
And you can see that when we're on the court, we get IP address of skilled Ahriman dot com is and you
can get IP address.
So this is basically what we've done in the past from the terminal.
But now you can see how professionally you can write it with an exception of an error message and with
very nice and stylish print statement with which you are showing your data.
So if you use this practice in writing your professional code, that would be absolutely great and the
way the code would look will be way better.
So I know that this visual guys was quite long, but I'm sure that you learned quite a lot of here,
a lot of things here, and that's it.
I really appreciate that you watched this video until the end and bear with me, because in the next
one, we're going to create the Tsipi client and server and you'll be able to do your first connection
to an actual server.
That's it.
Thank you very much for watching.
And I will see you in the next video.