WEBVTT

00:01.040 --> 00:01.360
Okay.

00:01.360 --> 00:02.160
Welcome back.

00:02.240 --> 00:13.000
In the previous lecture, we covered how to use the exit keyword to exit this program from running.

00:13.040 --> 00:14.040
Okay.

00:14.080 --> 00:17.160
Now again if I came back here if I do.

00:19.280 --> 00:24.680
Clear and execute this program and then go back to Windows Machine.

00:25.480 --> 00:31.800
And here again if I run this program, the reverse back to here.

00:31.800 --> 00:38.760
If I use a simple command like this, it is showing all the details within a folder okay.

00:38.800 --> 00:44.400
If I use exit command, you see it is exiting without any error.

00:44.400 --> 00:48.280
And also if I go back here now you see that it is also exited.

00:48.320 --> 00:53.600
Okay, so what if I use city command?

00:53.600 --> 00:56.640
You know that city command is not going to work here.

00:56.880 --> 01:04.820
We need to handle that separately here Into the listener and also the back door which is inside windows

01:04.820 --> 01:05.300
machine.

01:05.820 --> 01:16.020
So while we are here, okay, while we are sending this command, okay.

01:17.140 --> 01:25.660
Right here and then we are sending here the first one, which is just exit command right now.

01:26.780 --> 01:31.540
And in Windows Machine we are just receiving the first one, not the second one.

01:31.540 --> 01:41.020
For example, if I use city to desktop so I will be able to only receive or get the city command, not

01:41.020 --> 01:46.220
the second one which is the desktop.

01:46.860 --> 01:51.260
And if I remove this from here, this zero.

01:51.260 --> 02:03.760
So it is now this command will be a list and it will say that uh, command list do not have input uh

02:03.760 --> 02:05.040
attribute to use.

02:05.560 --> 02:10.680
So here we need to use another thing that is called JSON.

02:10.720 --> 02:10.920
Okay.

02:10.960 --> 02:13.800
For handling this we need to use JSON.

02:14.160 --> 02:18.120
So let's import that JSON here.

02:22.000 --> 02:24.920
Okay now I imported this.

02:25.280 --> 02:33.480
And here okay when I receive this this I need to serialize this data.

02:33.520 --> 02:34.640
Okay.

02:34.640 --> 02:41.520
So after I serialize this data then I can send this data.

02:41.560 --> 02:44.840
Not using this index okay.

02:44.880 --> 02:50.560
That means I can send the whole list from here to the back door.

02:50.600 --> 02:56.000
Okay, so how can I serialize this data?

02:56.480 --> 02:58.720
If you try to.

02:58.760 --> 03:07.930
If you want to know this, we have, uh, with, uh, JSON, we can use dump method that will handle

03:07.930 --> 03:08.450
this for us.

03:08.490 --> 03:08.850
Okay.

03:09.090 --> 03:10.730
So let's use serialize.

03:10.770 --> 03:11.290
Okay.

03:11.330 --> 03:14.970
Serialize the data.

03:15.930 --> 03:22.090
It is going to be equal to JSON dot dumps.

03:23.050 --> 03:30.970
And right here we are going to give the command because that is what we receive from user.

03:31.010 --> 03:31.810
Okay.

03:31.850 --> 03:32.970
So let's give it.

03:33.530 --> 03:33.810
Okay.

03:33.850 --> 03:42.170
Now we give this command to this um dumps method okay.

03:42.610 --> 03:43.130
And now.

03:45.370 --> 03:45.970
Okay.

03:46.010 --> 03:49.490
Or even I can do one more thing here.

03:51.010 --> 03:55.530
I can put this right here.

03:59.930 --> 04:01.550
And now I can use it again.

04:01.950 --> 04:03.350
Now it looks better.

04:03.870 --> 04:06.550
So.

04:08.590 --> 04:18.150
Okay, now that I'm trying to send this data using send function, we also have another method called

04:18.190 --> 04:21.590
send all okay with the socket.

04:21.990 --> 04:31.470
Now instead of sending the command I can send the serialized data dot encode okay.

04:33.350 --> 04:42.470
And now this serialized data had been sent by using send all method from here.

04:42.910 --> 04:47.910
So let me save this and let's go back to Windows Machine here.

04:47.910 --> 04:50.070
We need to handle that okay.

04:50.550 --> 04:55.790
Let me zoom this a little more okay.

04:55.790 --> 04:57.550
Here also we need to use two things.

04:57.550 --> 04:59.230
One of them is the OS module.

04:59.230 --> 05:04.930
The next one is um, uh, Jason again.

05:05.210 --> 05:08.330
Okay, so for that, we need to import that.

05:08.690 --> 05:12.770
So let's import JSON.

05:15.330 --> 05:17.530
And also import.

05:20.090 --> 05:20.690
OS.

05:20.970 --> 05:25.050
OS will allow you to use a system command.

05:25.330 --> 05:25.730
Okay.

05:27.090 --> 05:30.090
With your code within your code.

05:30.130 --> 05:35.610
Um, so we're trying to get that here.

05:35.650 --> 05:36.130
Okay.

05:36.170 --> 05:40.370
Actually, uh, we are receiving the command right here.

05:40.370 --> 05:47.290
And we're storing the command into inside a variable called commands here.

05:47.330 --> 05:52.370
Right now we are not going to receive that as byte.

05:52.410 --> 05:52.850
Okay.

05:54.370 --> 05:55.890
So I need to remove this.

05:57.370 --> 06:01.500
And also let's create another way.

06:01.540 --> 06:05.260
Another method here for handling this.

06:05.300 --> 06:05.500
Okay.

06:05.540 --> 06:06.740
So let's use div.

06:07.340 --> 06:13.020
Div of I'm going to name this changing or change working directory.

06:19.060 --> 06:19.860
To something.

06:20.500 --> 06:23.060
So here we need to provide the path.

06:23.100 --> 06:23.500
Okay.

06:25.020 --> 06:34.700
So after that I am going to use this OS dot Chdir means change directory to what to path.

06:35.100 --> 06:39.500
And at the end I need to return this path.

06:39.540 --> 06:42.220
Okay, after it is changed I need to return it.

06:42.220 --> 06:46.380
And here inside the run method I can use it okay.

06:47.580 --> 06:48.100
Okay.

06:48.140 --> 06:48.820
Perfect.

06:49.460 --> 06:51.580
So we have the command here.

06:51.620 --> 06:52.260
Okay.

06:52.340 --> 06:54.020
That is something we are receiving.

06:54.460 --> 06:58.100
So right now this is not a byte.

06:58.140 --> 07:00.060
It is serialized data.

07:00.560 --> 07:04.680
So when it is serialized data, we need to use again JSON.

07:04.720 --> 07:09.360
Okay, so let me create a variable here called data.

07:10.000 --> 07:17.120
Use JSON dot loads and give the commands to this.

07:17.600 --> 07:24.400
And now instead of using command here I can use data.

07:24.440 --> 07:27.840
And I can tell this that check for the first one.

07:27.840 --> 07:34.880
If the first one is equal to exit then close the connection.

07:35.960 --> 07:44.800
So this will check the first one and it will handle the exit method here.

07:45.440 --> 07:52.120
And now the main purpose of this lecture is to handle the city command.

07:52.160 --> 08:01.060
Okay so here let's use Elsif or Elif Elif data which is the first one.

08:01.060 --> 08:01.500
Okay.

08:02.980 --> 08:14.780
If this is equal to city that user enter and length of this data.

08:15.020 --> 08:21.340
The first one okay is greater than one okay.

08:21.380 --> 08:28.940
For example if it is two then I want this to be executed.

08:28.980 --> 08:29.860
Okay.

08:29.900 --> 08:30.220
All right.

08:30.260 --> 08:31.300
Now let's hit enter.

08:31.980 --> 08:39.460
Inside here I want to call that method that we just created called change working directory to something.

08:39.660 --> 08:40.500
Okay.

08:40.580 --> 08:45.980
So here let's again create another variable I am going to name this command result.

08:46.020 --> 08:52.420
It is equal to self dot change working directory to something.

08:53.020 --> 08:56.340
And that is data.

08:56.820 --> 08:59.460
So before we had zero okay.

08:59.500 --> 09:03.640
Because we need the we needed the first one now because we need the second one.

09:03.640 --> 09:06.280
So I'm going to use index one.

09:06.800 --> 09:10.720
And after I use this I need to encode this okay.

09:10.720 --> 09:16.880
So when it is encoded now I can use it again.

09:16.920 --> 09:23.240
So here we are going to use else.

09:23.240 --> 09:28.320
And we put this into else okay.

09:28.440 --> 09:33.800
Command result is equal to self dot execute command data.

09:33.800 --> 09:36.800
So I am sure it is going to work.

09:36.800 --> 09:39.480
Now let's save this.

09:39.480 --> 09:43.440
Let's go back to play machine.

09:43.800 --> 09:49.920
Let's go to cmd or terminal I am going to run the listener.

09:50.520 --> 09:53.680
Go back here again.

09:53.680 --> 09:55.040
Run this one.

09:55.320 --> 09:58.560
Let's go back here okay.

09:58.600 --> 10:00.200
Connection established.

10:00.860 --> 10:05.060
Now I'm going to use a simple command like dir that is not working.

10:05.540 --> 10:06.300
Perfect.

10:06.940 --> 10:08.700
What if I use city?

10:08.740 --> 10:09.260
It's not.

10:09.300 --> 10:10.780
I'm sure it's not going to work.

10:12.460 --> 10:18.100
So here, when we provide dir, it's returning non-zero status code one.

10:20.020 --> 10:21.940
We are having an error here.

10:22.940 --> 10:23.700
Let's see.

10:23.820 --> 10:24.980
What is that okay.

10:25.500 --> 10:33.060
So while we are sending this it is serialized data and it is encoded okay.

10:34.260 --> 10:34.780
So.

10:39.780 --> 10:48.500
I'm sure the problem is not right here because we are we may have some kind of error right in here that

10:48.500 --> 10:49.980
we need to handle that.

10:55.660 --> 10:56.100
Okay.

10:56.100 --> 10:59.460
We have the task city.

10:59.500 --> 11:00.060
Okay.

11:00.150 --> 11:01.390
Command result.

11:01.430 --> 11:02.870
We provide data here.

11:03.630 --> 11:05.310
Command result.

11:05.350 --> 11:06.710
System command.

11:06.870 --> 11:12.950
We provide the command here, which is not allowed to be used here.

11:12.990 --> 11:13.350
Okay.

11:13.390 --> 11:21.910
Here we need to give data instead of commands because here we change the commands to data.

11:21.950 --> 11:22.310
Okay.

11:22.910 --> 11:26.430
Now let me save this again and let's go back to.

11:29.350 --> 11:29.670
Scala.

11:29.670 --> 11:30.190
Linux.

11:31.030 --> 11:32.470
We execute the program.

11:34.830 --> 11:36.510
And come to windows.

11:39.550 --> 11:40.630
Run this again.

11:41.950 --> 11:42.790
Come back here.

11:42.790 --> 11:45.070
So the connection is established.

11:45.350 --> 11:49.790
Now let's use dir which is a simple command is working.

11:49.990 --> 11:50.390
Okay.

11:50.790 --> 11:53.950
Now I'm going to use Siri to go back.

11:53.990 --> 11:54.430
Okay.

11:54.470 --> 11:57.710
One step back and hit enter.

11:57.990 --> 11:59.950
So it is giving me this one.

12:00.030 --> 12:04.290
That is because I use return here.

12:04.330 --> 12:04.530
Okay.

12:04.570 --> 12:05.890
I'm returning the path.

12:06.170 --> 12:09.850
And after I return the path somewhere here.

12:10.130 --> 12:10.650
Okay.

12:10.690 --> 12:11.890
And then back.

12:11.890 --> 12:20.090
I send this to, uh, the listener and in listener here, I print that.

12:20.090 --> 12:22.450
Okay, I receive it.

12:22.530 --> 12:25.010
And after I receive it, I print that here.

12:25.570 --> 12:29.890
So because of that, it is printing that for me.

12:30.050 --> 12:39.610
Now if again I use dir, you see that we change the directory to this one to this store before it was

12:40.010 --> 12:41.050
Python project.

12:41.090 --> 12:44.090
Now it is this one.

12:44.090 --> 12:49.170
Let's use uh, I want to go back to for example exploit.

12:49.650 --> 12:54.450
I use Siri and now I use dir.

12:54.490 --> 12:59.930
You see, this time we are into exploit cheap and I can go to any of them.

12:59.930 --> 13:00.070
For them.

13:00.070 --> 13:02.110
For example, I want to go to document.

13:02.670 --> 13:03.070
Okay.

13:03.110 --> 13:11.750
So use d o c u m e n t s uh documents.

13:11.750 --> 13:17.950
I think we did not move to writing here.

13:17.990 --> 13:19.070
Let's use dir.

13:20.070 --> 13:20.350
Okay.

13:20.390 --> 13:22.710
We are into here.

13:22.750 --> 13:28.870
Looks like because we have that use city hit enter.

13:31.230 --> 13:36.310
So now you see we are into that document okay.

13:39.550 --> 13:43.990
Let's see if the program is still working on windows Machine or it's closed.

13:44.030 --> 13:46.230
See it is still working bad.

13:47.430 --> 13:48.990
That that means it is working.

13:48.990 --> 13:53.390
Okay, let's go back to here.

13:53.630 --> 13:54.350
Okay.

13:54.390 --> 13:56.910
I want to go back to desktop.

13:58.630 --> 13:59.590
Desktop.

13:59.630 --> 14:05.640
Hit It enter the air and I want to go to.

14:09.080 --> 14:10.800
Looks like it is not working.

14:12.000 --> 14:13.200
Disk up.

14:13.600 --> 14:14.080
Okay.

14:14.120 --> 14:15.160
It is working right now.

14:15.160 --> 14:21.800
You see, it is giving me an error because I am into the desktop and I'm asking for desktop.

14:22.200 --> 14:25.440
So because of that now the program is broken.

14:25.440 --> 14:27.840
And also here the program is broken.

14:29.040 --> 14:33.960
That means it is saying the system cannot find the file that you give that.

14:33.960 --> 14:39.520
Is this because right now the location you are looking for is inside the desktop.

14:39.520 --> 14:43.080
So that means it is working perfect.

14:43.200 --> 14:48.200
Okay, let's try this once again.

14:48.240 --> 14:53.600
Run the program.

14:53.640 --> 14:54.720
Run this one.

14:55.320 --> 15:01.860
Let me go back here I use d I r right now I am into Python project.

15:01.860 --> 15:02.260
Okay.

15:02.660 --> 15:08.140
I use city to come back here if I use dir.

15:08.220 --> 15:13.500
Now you see I am into desktop instead of being in Python project.

15:13.620 --> 15:17.020
Let's go back again here.

15:17.060 --> 15:20.340
Now I am into exploit cheap instead of being right there.

15:20.860 --> 15:22.700
So let me use city.

15:22.740 --> 15:26.220
For example, I want to go back to Windows machine.

15:26.660 --> 15:30.940
I don't know if in windows we use this kind of slash or this one.

15:30.940 --> 15:32.060
I don't know exactly.

15:32.460 --> 15:33.380
Let's try that.

15:33.380 --> 15:34.940
This top hit.

15:34.940 --> 15:36.100
Enter.

15:36.140 --> 15:36.780
Dir.

15:37.420 --> 15:37.940
Dir.

15:38.860 --> 15:40.500
And it's not working.

15:41.540 --> 15:42.220
No problem.

15:42.900 --> 15:52.980
But the program that we are trying to work trying to use now, it is completed and it is working okay.

15:53.020 --> 15:56.380
We can change our directories that we want.

15:56.420 --> 16:00.220
So thanks for watching and I will see you in the next lecture.
