1 00:00:04,910 --> 00:00:07,000 Getting false information. 2 00:00:07,210 --> 00:00:08,020 Hi, everyone. 3 00:00:08,560 --> 00:00:10,390 Welcome back to the course today. 4 00:00:10,480 --> 00:00:14,670 We're going to go straight to coding and for that reason, a terminal. 5 00:00:14,860 --> 00:00:16,290 So here is our terminal. 6 00:00:16,720 --> 00:00:21,330 Let's make it a bit bigger so you can see what I'm typing in here. 7 00:00:21,340 --> 00:00:27,340 We're going to try some comments in order to see the force that we are going to be using in that course. 8 00:00:28,090 --> 00:00:33,000 So the first thing I will do is I will go to python mode. 9 00:00:33,130 --> 00:00:40,650 So Python here and now we're in python mode and I'll write import sockets, OK? 10 00:00:41,020 --> 00:00:45,570 And usually I think everybody would have the socket package already installed. 11 00:00:45,850 --> 00:00:51,850 But if you don't have it installed, you already know how to install packages just by pipe install and 12 00:00:51,850 --> 00:00:53,770 the socket package anyways. 13 00:00:54,190 --> 00:01:00,610 So now let's write a command that will basically show you the type of the socket we have. 14 00:01:00,850 --> 00:01:04,820 As I said, the sockets are marked by fourth numbers. 15 00:01:04,840 --> 00:01:09,460 So for example, if I write socket dot get. 16 00:01:10,530 --> 00:01:15,410 Server by four and right port 80. 17 00:01:15,690 --> 00:01:17,730 OK, let me fix my mistake. 18 00:01:17,910 --> 00:01:21,270 Yes, it's get serve Bayport, right? 19 00:01:21,840 --> 00:01:22,380 Yes. 20 00:01:22,380 --> 00:01:27,880 So if I get served by Porth a team, you can see that on eight. 21 00:01:27,960 --> 00:01:32,790 We have the HTP protocol or for example, if I write the same. 22 00:01:34,010 --> 00:01:38,810 Socket not get served by. 23 00:01:40,220 --> 00:01:43,470 Brought by port. 24 00:01:43,930 --> 00:01:49,750 OK, get there by port, and if we're right or to end the trip, you can see that port when the trip 25 00:01:49,750 --> 00:01:55,800 is telnet and then it is actually a function that enables you to connect to different machines that 26 00:01:55,810 --> 00:01:56,080 are. 27 00:01:57,060 --> 00:02:04,050 Attached to your current machine, but anyways, this is the way that you can actually see the different 28 00:02:04,050 --> 00:02:09,360 types of products on the different parts, but let's actually create a script that will show you all 29 00:02:09,360 --> 00:02:10,370 this instantly. 30 00:02:10,590 --> 00:02:12,720 And for that reason, I open by charm. 31 00:02:13,590 --> 00:02:15,390 So let's open the chart here. 32 00:02:15,540 --> 00:02:17,780 So let's hit the resources folder here. 33 00:02:18,180 --> 00:02:22,620 And of course, I will create a new folder, which will be called Section six. 34 00:02:22,920 --> 00:02:24,540 But let's wait to load a bit. 35 00:02:24,570 --> 00:02:33,750 So let's create in our resources folder a new directory, which is going to be called Section six. 36 00:02:34,060 --> 00:02:40,140 OK, and now a Section six who are going to be able to create our new files, which are only going to 37 00:02:40,140 --> 00:02:42,120 be related to sockets. 38 00:02:42,540 --> 00:02:43,290 So. 39 00:02:44,470 --> 00:02:50,050 Now, I will create the first file and in this file, guys, and this will be a -- and it will 40 00:02:50,050 --> 00:02:52,030 check all the reports in their names. 41 00:02:52,240 --> 00:02:53,530 So the name will be. 42 00:02:54,760 --> 00:02:55,360 Show. 43 00:02:56,620 --> 00:03:03,160 Ports, OK, and don't worry, even though just FYI, we want to show the ports later on in the course, 44 00:03:03,160 --> 00:03:09,790 we'll create our own server and our own client and I will show you how they can exchange information 45 00:03:09,790 --> 00:03:10,940 simultaneously. 46 00:03:11,530 --> 00:03:22,570 So let's right here, user Bill Ian V Slash without slash Python three. 47 00:03:23,980 --> 00:03:26,450 And then let's import sockets. 48 00:03:27,160 --> 00:03:37,840 OK, and after that, I will write a simple function which will be called So Def Find, Serve, Serve. 49 00:03:39,160 --> 00:03:45,920 Name or fanservice name, and this function will not take any argument. 50 00:03:46,180 --> 00:03:52,890 So let's first create a variable which will be called Perreault Taco Name. 51 00:03:53,140 --> 00:03:57,080 OK, and this will be equal to TCAP. 52 00:03:57,220 --> 00:03:59,090 So this is a Tsipi protocol. 53 00:03:59,170 --> 00:04:04,360 OK, and then I will write for 14. 54 00:04:06,190 --> 00:04:10,810 The range of 80 and 25. 55 00:04:12,190 --> 00:04:19,330 What we would like to do is to print for them percent is in here, you can do like that. 56 00:04:20,510 --> 00:04:22,920 OK, this simpleton's. 57 00:04:24,730 --> 00:04:25,780 Service. 58 00:04:26,780 --> 00:04:27,410 Name. 59 00:04:29,480 --> 00:04:37,580 OK, and then here again, percent is OK, and now the percent S's are going to be related to the following 60 00:04:37,580 --> 00:04:38,020 things. 61 00:04:38,450 --> 00:04:46,540 So here I our right board, OK, which is the name of the variable that we passed. 62 00:04:46,760 --> 00:04:52,520 So it will be either 80 or twenty five and then socket dot. 63 00:04:54,350 --> 00:04:56,300 Get serve. 64 00:04:57,310 --> 00:04:57,880 By. 65 00:05:00,380 --> 00:05:01,520 Bayport. 66 00:05:03,680 --> 00:05:06,770 OK, get served by in here. 67 00:05:06,800 --> 00:05:11,450 All right, Port, so it takes a number of the port and then. 68 00:05:13,390 --> 00:05:14,570 Protocol name. 69 00:05:14,780 --> 00:05:22,290 OK, so the protocol name here is the Tsipi, and the first name will be first 80 and then 25. 70 00:05:22,420 --> 00:05:22,840 OK. 71 00:05:24,380 --> 00:05:30,740 So we're done here, guys, and then I will create another statement, but this statement will be. 72 00:05:32,320 --> 00:05:35,530 Actually, outside of the Falu, so. 73 00:05:36,810 --> 00:05:43,980 Here, I will print, so I will print actually with Capital Port and then as. 74 00:05:45,920 --> 00:05:52,220 And basically, we're going to do a similar thing here, so I write service. 75 00:05:53,470 --> 00:05:54,070 Name. 76 00:05:54,460 --> 00:05:54,950 OK. 77 00:05:56,140 --> 00:05:58,270 And then I can present is. 78 00:06:00,260 --> 00:06:09,530 And here, the percentages would be actually the first fifty three and then socket not. 79 00:06:10,620 --> 00:06:12,600 You get several Bayport. 80 00:06:13,970 --> 00:06:24,920 And then 53 and then you, DP, OK, and why we're doing this separately, this is because the participant 81 00:06:24,920 --> 00:06:27,160 actually has two types. 82 00:06:27,560 --> 00:06:32,360 Why would you report we're only going to support 53 here? 83 00:06:32,480 --> 00:06:37,650 OK, this is the reason why would we just separately want within the for loop and the other one without. 84 00:06:38,390 --> 00:06:40,230 So let's actually run this function. 85 00:06:40,250 --> 00:06:43,430 So let's try the standard if name. 86 00:06:45,220 --> 00:06:48,700 Equals Main, then find. 87 00:06:50,310 --> 00:06:51,210 Service name. 88 00:06:51,760 --> 00:06:56,530 OK, so this is the function that is going to be running. 89 00:06:56,910 --> 00:07:01,060 And now let's save that and I will go back to here. 90 00:07:01,170 --> 00:07:02,300 Let's exit. 91 00:07:03,210 --> 00:07:04,260 So control. 92 00:07:05,760 --> 00:07:09,900 OK, and I'll go to the folder that I have this file installed. 93 00:07:10,030 --> 00:07:14,100 And when I write a wish, you can see the support file here. 94 00:07:14,190 --> 00:07:17,370 So let's copy it and I'll write Python. 95 00:07:17,370 --> 00:07:18,420 And let's face it. 96 00:07:19,740 --> 00:07:27,660 And you can see that guys here, we're actually getting so caught 80 and we see the service name is 97 00:07:27,660 --> 00:07:36,270 HTP and then we get the service name of twenty five that is SMPTE P and finally we're getting the service 98 00:07:36,270 --> 00:07:37,190 name of the port. 99 00:07:37,470 --> 00:07:39,120 Fifty three, which is our domain. 100 00:07:39,680 --> 00:07:47,120 OK, so the domain is actually the UDP port or UDP type of the protocol. 101 00:07:47,460 --> 00:07:52,860 So on the site you can also check on the port name of a web page. 102 00:07:52,860 --> 00:08:01,320 And for that reason let's actually create another file and let's create new light on file in the name 103 00:08:01,320 --> 00:08:03,000 of this file will be get. 104 00:08:04,210 --> 00:08:05,020 Address. 105 00:08:05,380 --> 00:08:15,880 OK, so let's right here, slash user slash being slash Ian Ian fee. 106 00:08:17,660 --> 00:08:21,100 Python three and let's import socket. 107 00:08:21,300 --> 00:08:26,930 OK, and what we're going to do here is simply to get a new form of a website. 108 00:08:27,110 --> 00:08:34,520 So let's do a tri statement so we ensure that if we don't find the website, we will get the correct 109 00:08:34,520 --> 00:08:34,860 error. 110 00:08:35,180 --> 00:08:46,880 So I will do try and then here I'll write in full list will be equal to socket dot get server Bayport. 111 00:08:46,880 --> 00:08:51,020 Actually let's do it differently and get others to follow. 112 00:08:51,980 --> 00:08:58,670 And here in the ultrasound for first of all I read the website so this will be skewed. 113 00:08:59,300 --> 00:09:11,390 R.M. dot com then double double w ok coma's zero then Cómo socket dot sockets stream. 114 00:09:11,570 --> 00:09:16,820 OK, so, so this room will actually take the stream of data from the website. 115 00:09:17,210 --> 00:09:17,870 The Zero. 116 00:09:19,710 --> 00:09:21,750 And then let's try the circuit. 117 00:09:23,400 --> 00:09:24,810 That's a. 118 00:09:26,570 --> 00:09:35,810 Underscore article, then this right here, the socket, not a. 119 00:09:38,070 --> 00:09:45,270 Underscore the so here is socket, I underscore V. 120 00:09:47,130 --> 00:09:53,940 Four months and then another pipe and the pipes to actually separate the different information. 121 00:09:53,970 --> 00:09:58,490 So this right here socket, not a. 122 00:09:59,900 --> 00:10:06,410 Underscore can name calling and that to the guys here. 123 00:10:07,510 --> 00:10:10,220 Now, let's right, except. 124 00:10:10,960 --> 00:10:16,760 OK, so this is the exception, and they are right here, socket Dr. Gaier. 125 00:10:18,450 --> 00:10:19,460 US e. 126 00:10:19,860 --> 00:10:23,310 OK, so if we were still there, who would like to print here? 127 00:10:25,580 --> 00:10:27,710 Name service. 128 00:10:29,040 --> 00:10:29,790 Failure. 129 00:10:31,490 --> 00:10:34,910 Then Colma idot args. 130 00:10:35,520 --> 00:10:36,040 OK. 131 00:10:36,870 --> 00:10:39,660 And then I will write one here and then. 132 00:10:39,660 --> 00:10:42,720 That's right sis dot exit. 133 00:10:44,480 --> 00:10:46,810 And we're just on one, that's it. 134 00:10:47,990 --> 00:10:54,020 OK, so let's right now here info will be equal to Infl. 135 00:10:55,430 --> 00:10:57,980 List and then zero. 136 00:10:58,520 --> 00:11:05,040 OK, and then let's try to print in full list and actually here's capital letter, OK, awfullest, 137 00:11:05,150 --> 00:11:06,200 that's it then. 138 00:11:06,200 --> 00:11:16,760 Let's write sockets underscore our X will be equal to in full and zero to three. 139 00:11:16,970 --> 00:11:24,620 OK, so this is our Socotra list and we have the input data from zero to three and. 140 00:11:25,730 --> 00:11:32,960 As you can see, the parameter, because the data from the fullest ADIRU position and obviously here 141 00:11:32,960 --> 00:11:38,210 we will hear from Matrixx on their position will have a certain amount of arguments which are on the 142 00:11:38,210 --> 00:11:38,810 same line. 143 00:11:38,810 --> 00:11:41,410 And we will see exactly them then. 144 00:11:41,570 --> 00:11:44,510 And let's try and address the course info. 145 00:11:45,860 --> 00:11:51,620 Four and then as will be equal to circuit. 146 00:11:53,170 --> 00:11:57,840 That socket and here I will write the. 147 00:11:59,860 --> 00:12:00,610 Star. 148 00:12:02,460 --> 00:12:03,330 Circuit. 149 00:12:05,650 --> 00:12:06,030 OK. 150 00:12:07,050 --> 00:12:15,960 And then let's try to narrow exception that be a short one, so let's try to try as dots connect and 151 00:12:15,960 --> 00:12:28,140 then here was the address and let's write exception or accept circuit adult error as E and here print 152 00:12:28,180 --> 00:12:29,300 actually their message. 153 00:12:29,580 --> 00:12:31,740 So I write network. 154 00:12:33,410 --> 00:12:34,250 Failure. 155 00:12:34,940 --> 00:12:35,330 OK. 156 00:12:36,020 --> 00:12:39,880 And after that, this right dot ARC's. 157 00:12:41,780 --> 00:12:45,310 One and then else. 158 00:12:45,530 --> 00:12:51,320 So if we get any clearer who print or actually if we don't get there, all princesses. 159 00:12:52,190 --> 00:12:56,990 Host Cuomo Info three. 160 00:12:59,040 --> 00:13:04,020 OK, so the infantry is going to go to the horse and we're right is. 161 00:13:05,230 --> 00:13:09,430 Is listening on board eight. 162 00:13:09,700 --> 00:13:14,770 OK, let's say up in this, try to run the code now, first of all, as Right Airways and as you can 163 00:13:14,770 --> 00:13:18,000 see here, you can see get out of this script. 164 00:13:18,010 --> 00:13:21,760 So let's write Python and get the address. 165 00:13:22,090 --> 00:13:25,300 And you can see that our code is running successfully, guys. 166 00:13:25,660 --> 00:13:32,560 So you can see here that, first of all, the first very important thing to notice is that we have a 167 00:13:32,560 --> 00:13:33,160 success. 168 00:13:33,400 --> 00:13:37,320 So this is the last syntax that we just wrote here. 169 00:13:37,500 --> 00:13:46,240 Let me make this more actually, so you can see success cost Scutari dot com, which is for Dautry is 170 00:13:46,240 --> 00:13:50,330 listening Conforth eight, which is the port we actually opened to the server. 171 00:13:50,390 --> 00:14:01,150 OK, this is our socket and you can see the data here that we get Alturas family dot A.F. in it, which 172 00:14:01,150 --> 00:14:03,930 is the one we stated right here. 173 00:14:04,270 --> 00:14:07,240 So we're getting there in it too. 174 00:14:07,540 --> 00:14:11,830 Then we're getting the socket kind and the socket stream. 175 00:14:11,980 --> 00:14:12,510 OK. 176 00:14:14,050 --> 00:14:20,310 We get the name of the port, we get also the IP address and the port that is opened. 177 00:14:20,430 --> 00:14:26,570 OK, so this is how you can actually connect to a website and see the port that is open to that website 178 00:14:26,840 --> 00:14:30,670 and potentially do some controls on it. 179 00:14:31,100 --> 00:14:37,970 But as you can see, you cannot only stick to opening servicing clients in your computer, but also 180 00:14:37,970 --> 00:14:41,870 to accessing different websites located on the Web. 181 00:14:41,990 --> 00:14:44,250 And I can also prove this in another way. 182 00:14:44,270 --> 00:14:57,560 So if write item here and if we simply write import to socket and then if a right socket dot get caused 183 00:14:57,800 --> 00:14:58,220 by. 184 00:14:59,660 --> 00:15:00,230 Name. 185 00:15:00,560 --> 00:15:08,300 OK, get hosed by name and then the right name of a website like Skilled Army dot com. 186 00:15:08,600 --> 00:15:15,650 OK, you will see that you are immediately getting the IP address of the Scutari dot com. 187 00:15:15,650 --> 00:15:21,560 Or let's try another website that you definitely use, YouTube dot com. 188 00:15:22,190 --> 00:15:28,130 And you can see that you're getting the IP of the YouTube dot com, which is a hundred seventy two to 189 00:15:28,160 --> 00:15:30,550 seventeen dot for dot forty six. 190 00:15:30,860 --> 00:15:36,920 So this is a very easy way to get the IP addresses using sockets and connect to different web pages. 191 00:15:37,190 --> 00:15:45,140 And if you actually want to get the full information for a website, you can actually do it within less 192 00:15:45,140 --> 00:15:47,500 than ten lines of code and I will show you how it's done. 193 00:15:47,840 --> 00:15:51,850 So let's create another Python file and here I will. 194 00:15:51,860 --> 00:15:53,240 Kowit get. 195 00:15:54,400 --> 00:15:55,980 Well, OK. 196 00:15:57,620 --> 00:16:02,930 So you can see how easy it is actually to write a simple script and get the information off a website. 197 00:16:03,200 --> 00:16:14,360 So if I write again, user slash, bean slash E and the V Python three and then you four import sockets, 198 00:16:14,870 --> 00:16:20,910 you can then write a D get underscore remold info. 199 00:16:21,380 --> 00:16:36,530 OK, and here if I write remote, underscore costs and let the remote holes be skilled rmv dot com and 200 00:16:36,530 --> 00:16:36,990 I'll write. 201 00:16:37,010 --> 00:16:44,270 I would, I would, I would not secure ami dot com and then let's do it as an exception so it's easier 202 00:16:45,020 --> 00:16:49,660 for the computer, for the program to cope with our code. 203 00:16:49,670 --> 00:16:57,170 So let's print here and I will show how you can immediately print here all the information you need 204 00:16:57,170 --> 00:16:57,940 for the website. 205 00:16:57,950 --> 00:17:07,400 If I write IP address of person s and then outside I will again write percent. 206 00:17:08,350 --> 00:17:09,350 Percent, yes. 207 00:17:09,640 --> 00:17:19,470 OK, so that could be done by writing two percent and the first percent will be the remote coast. 208 00:17:20,070 --> 00:17:22,480 OK, the one that you stated earlier on. 209 00:17:22,480 --> 00:17:26,460 So it will be Scutaro dot com and this is the host passing. 210 00:17:26,470 --> 00:17:37,240 And then we can write circuits that get hostname and you can write inside Remote Coast. 211 00:17:37,280 --> 00:17:43,060 OK, so we are getting here today, pylorus of the host, obviously, and this is how actually you can 212 00:17:43,060 --> 00:17:46,960 write a script to get the IP address and all the information you need. 213 00:17:47,060 --> 00:17:48,760 And now let's do. 214 00:17:49,930 --> 00:18:00,340 Except for exception in the socket, that error was er a message for message. 215 00:18:00,410 --> 00:18:10,120 OK, and let's right here print and let's right here the error message so percent is OK and 10 percent 216 00:18:10,120 --> 00:18:13,520 is in on the placeholder percent. 217 00:18:13,540 --> 00:18:24,460 I will just state the remote host's so remote host and then error message that will be passed. 218 00:18:24,590 --> 00:18:27,950 OK, and finally let's just run the function. 219 00:18:27,970 --> 00:18:30,340 So if name. 220 00:18:31,750 --> 00:18:33,320 Equals Main. 221 00:18:33,640 --> 00:18:39,850 OK, so if name equals Main, they would like to run the function, which is called to get the remote 222 00:18:39,850 --> 00:18:40,350 info. 223 00:18:40,570 --> 00:18:49,030 OK, let's say that by pressing the controllers in, I will also exit the python mode here and you should 224 00:18:49,030 --> 00:18:52,450 be in your Section six folder in order to run the file. 225 00:18:52,750 --> 00:18:57,790 So far, right away, as you can see that the gateway file was here, so. 226 00:18:57,790 --> 00:18:59,800 Right, Python. 227 00:19:00,870 --> 00:19:01,530 You get. 228 00:19:02,460 --> 00:19:03,030 Web. 229 00:19:04,370 --> 00:19:09,260 OK, for one of the guys you can see there are some mirrors, so let's go back to the court and just 230 00:19:09,260 --> 00:19:09,920 address them. 231 00:19:10,460 --> 00:19:17,870 And if I go back, I can actually see where there is because we need to right here get hosted by name, 232 00:19:18,770 --> 00:19:20,350 but not get hostname. 233 00:19:20,540 --> 00:19:23,210 OK, so I will delete of this. 234 00:19:23,720 --> 00:19:24,620 Let's save it. 235 00:19:24,860 --> 00:19:31,550 And you can see that when we're on the court, we get IP address of skilled Ahriman dot com is and you 236 00:19:31,550 --> 00:19:32,750 can get IP address. 237 00:19:32,760 --> 00:19:36,770 So this is basically what we've done in the past from the terminal. 238 00:19:36,770 --> 00:19:43,460 But now you can see how professionally you can write it with an exception of an error message and with 239 00:19:44,210 --> 00:19:49,280 very nice and stylish print statement with which you are showing your data. 240 00:19:49,670 --> 00:19:56,000 So if you use this practice in writing your professional code, that would be absolutely great and the 241 00:19:56,000 --> 00:19:58,880 way the code would look will be way better. 242 00:19:59,790 --> 00:20:05,360 So I know that this visual guys was quite long, but I'm sure that you learned quite a lot of here, 243 00:20:05,600 --> 00:20:07,880 a lot of things here, and that's it. 244 00:20:07,880 --> 00:20:12,890 I really appreciate that you watched this video until the end and bear with me, because in the next 245 00:20:12,890 --> 00:20:19,940 one, we're going to create the Tsipi client and server and you'll be able to do your first connection 246 00:20:19,940 --> 00:20:20,990 to an actual server. 247 00:20:21,380 --> 00:20:21,920 That's it. 248 00:20:21,930 --> 00:20:23,240 Thank you very much for watching. 249 00:20:23,240 --> 00:20:25,010 And I will see you in the next video.