1 00:00:04,820 --> 00:00:07,010 Port scanning would sockets. 2 00:00:07,040 --> 00:00:07,550 Hi, guys. 3 00:00:07,580 --> 00:00:08,930 And welcome back to the course. 4 00:00:10,130 --> 00:00:17,390 I must tell you that sometimes you are going to be using so many ports that you actually want to be 5 00:00:17,390 --> 00:00:22,520 able to see which port is connected and which port is not connected. 6 00:00:22,940 --> 00:00:29,510 And for that reason, you want to check the connection on each port and if it's actually connected to 7 00:00:29,510 --> 00:00:30,470 certain server. 8 00:00:30,590 --> 00:00:30,950 Right. 9 00:00:31,310 --> 00:00:36,540 So for that reason, I'm going to show you a very simple script with which you can check that. 10 00:00:37,010 --> 00:00:39,890 And let's create here a new Python file. 11 00:00:40,280 --> 00:00:43,850 And this will be called Scan Port. 12 00:00:44,120 --> 00:00:44,490 OK. 13 00:00:46,100 --> 00:00:51,590 And the court has heard a few lies, but it's actually quite useful and they always use it in order 14 00:00:51,590 --> 00:00:53,050 to check my connections. 15 00:00:53,360 --> 00:00:55,880 So let me first do the usual stuff. 16 00:00:56,870 --> 00:01:00,770 Yuzu been in V. 17 00:01:01,730 --> 00:01:03,380 And then item. 18 00:01:04,570 --> 00:01:05,050 Three. 19 00:01:05,320 --> 00:01:17,230 OK, and let me enable the syntax, so let's import circuit and let's do IP address will be equal to 20 00:01:17,260 --> 00:01:17,980 input. 21 00:01:18,190 --> 00:01:21,240 And here we are going to type our IP address. 22 00:01:21,550 --> 00:01:25,720 So let's write enter IP. 23 00:01:27,320 --> 00:01:29,570 Address for port. 24 00:01:30,820 --> 00:01:31,550 Scanning. 25 00:01:31,600 --> 00:01:40,000 OK, so here you enter an IP address and let's write or underscore. 26 00:01:41,350 --> 00:01:44,830 In it to be equal to again in. 27 00:01:45,460 --> 00:01:49,270 That's right, enter first sports, OK? 28 00:01:49,570 --> 00:01:52,970 And after that, let's fight for it. 29 00:01:53,000 --> 00:01:58,180 And and here I will do in sports and then. 30 00:01:58,480 --> 00:02:00,900 And third, last fourth. 31 00:02:00,920 --> 00:02:07,160 So we're going to check from the first last sport report if it has the right connection or not. 32 00:02:07,720 --> 00:02:11,830 So obviously here we need to create a for loop for each sport. 33 00:02:12,070 --> 00:02:17,110 And then we're right for sports in range. 34 00:02:17,650 --> 00:02:21,960 And the range is going to be from the first to the last sport. 35 00:02:22,270 --> 00:02:31,180 So I will do sport in it here supporting it and then the last sport in the range. 36 00:02:32,590 --> 00:02:42,760 So Colma Integer and the last port in the range will be the port and OK and here will add one as well. 37 00:02:43,900 --> 00:02:52,980 OK, so for each of the ports that remark will create a soc variable which will be equal to socket n 38 00:02:53,230 --> 00:02:56,080 socket and then in the brackets. 39 00:02:57,920 --> 00:03:08,410 A socket, a dot, a if I net and then socket that so extreme. 40 00:03:09,180 --> 00:03:09,640 OK. 41 00:03:10,650 --> 00:03:17,100 And after that I would also not sit by mouth in here we'll have five. 42 00:03:17,220 --> 00:03:32,490 And then the results actually result will be equal to soak, dot connect actually to connect X for external. 43 00:03:32,790 --> 00:03:39,170 And here I'll write IP address coma for OK. 44 00:03:40,380 --> 00:03:48,630 And then if the result is equal to zero then we'll write Prince Port Colma. 45 00:03:48,900 --> 00:03:56,340 Let's write open here so we can see the other so on and let's write so else. 46 00:03:56,490 --> 00:04:05,040 OK or if the port is close to print here Port Como and then you see that the port is actually closed. 47 00:04:05,040 --> 00:04:13,100 So I would close OK and then suck that close and we already here. 48 00:04:13,470 --> 00:04:21,390 So let's not try to run the actual code and see if we can get the connection and if our port will be 49 00:04:21,390 --> 00:04:21,750 running. 50 00:04:21,870 --> 00:04:32,580 So let's write aways and here where is OK so ports can port to Python. 51 00:04:34,170 --> 00:04:41,820 And then scan port in those you can see first who are asked for IP address, but the main source of 52 00:04:41,820 --> 00:04:43,020 fans who are right about that. 53 00:04:43,050 --> 00:04:47,190 What about that killed Army dot com? 54 00:04:48,510 --> 00:04:52,180 Let's run it and here we will be checking the port. 55 00:04:52,230 --> 00:04:59,810 So let's enter the ports from 80 to 85 and you can see that we got information very fast. 56 00:05:00,120 --> 00:05:06,780 So you can see that now we have connection Port 80 and we have it with the server, Scutaro dot com 57 00:05:07,050 --> 00:05:08,280 in the rest of the ports. 58 00:05:08,280 --> 00:05:09,150 They are closed. 59 00:05:09,550 --> 00:05:11,980 Let's do it again so you can see how it happens. 60 00:05:12,210 --> 00:05:13,310 Let's go on our website. 61 00:05:13,330 --> 00:05:26,040 Actually, that would allow that YouTube dot com and the first port will be, let's do it, 79 to 86. 62 00:05:26,220 --> 00:05:30,120 And you can see that information takes way longer than us. 63 00:05:30,450 --> 00:05:33,630 YouTube dot com, I guess, is slightly heavier. 64 00:05:34,050 --> 00:05:35,940 But you can see that now. 65 00:05:35,940 --> 00:05:38,190 Again, we get the information data. 66 00:05:38,520 --> 00:05:40,940 So we're connecting to YouTube dot com. 67 00:05:41,430 --> 00:05:49,290 And this is the way, guys, you can always check if you're connected to a certain website or if certain 68 00:05:49,290 --> 00:05:50,330 port is busy. 69 00:05:50,670 --> 00:05:58,390 And this was everything I want to share with you for today, for our connectivity and how you can scan 70 00:05:58,410 --> 00:05:59,220 different ports. 71 00:05:59,550 --> 00:06:02,790 Thanks for watching and I'll see you in the next video.