WEBVTT

00:01.360 --> 00:05.880
Now to get this result.

00:05.920 --> 00:06.240
Okay.

00:06.280 --> 00:12.600
Or this Mac address from output which is stored in ifconfig result.

00:12.640 --> 00:12.920
Okay.

00:12.960 --> 00:17.440
We are going to use a module called regex or re.

00:17.480 --> 00:19.480
So let's import that okay.

00:19.520 --> 00:20.880
Import re.

00:21.400 --> 00:25.120
So okay so now we have imported this.

00:25.120 --> 00:27.000
Maybe it is not already installed.

00:27.040 --> 00:27.320
Okay.

00:27.360 --> 00:37.440
So if you want to install this so let me go to here use pip install re.

00:37.680 --> 00:39.760
So this will be installed okay.

00:39.800 --> 00:41.520
If we have internet connection.

00:41.720 --> 00:43.040
So it will be installed.

00:43.040 --> 00:45.480
If we don't have it no problem.

00:45.600 --> 00:49.960
Let we will we will install that okay.

00:50.000 --> 00:53.880
So as you see it is it has another color okay.

00:53.920 --> 00:54.680
Change color.

00:54.680 --> 00:58.640
So maybe it is not installed okay.

00:58.640 --> 01:00.320
So we're going to use from that.

01:00.320 --> 01:04.120
And that Re has a function that is called search.

01:04.720 --> 01:05.360
Very easy.

01:05.400 --> 01:05.720
Okay.

01:07.720 --> 01:12.080
Now let's use that re dot search.

01:12.640 --> 01:13.040
Okay.

01:13.520 --> 01:16.520
Here we are going to provide the regex.

01:16.560 --> 01:16.960
Okay.

01:17.280 --> 01:24.520
So in here I am going to give the regex pattern that I just created here.

01:24.960 --> 01:26.520
Let me copy this.

01:29.520 --> 01:32.240
And go back to curly.

01:32.280 --> 01:35.480
Here I'm going to paste this.

01:35.600 --> 01:36.000
Okay.

01:36.280 --> 01:39.560
So this is the first argument that search accepts.

01:39.560 --> 01:46.400
And the next one is uh the resource or where do you want to search this.

01:46.440 --> 01:46.760
Okay.

01:46.800 --> 01:51.800
We are going to search this pattern into this variable which is if config result.

01:51.920 --> 01:52.840
Very good.

01:52.880 --> 01:56.040
So you need to give the if config result right here.

01:56.640 --> 01:57.040
Okay.

01:57.280 --> 02:00.280
If config result.

02:01.280 --> 02:02.720
So there we go.

02:02.760 --> 02:04.040
Now we have it here.

02:04.040 --> 02:06.960
And it is better to store this into a variable.

02:07.000 --> 02:07.240
Okay.

02:07.280 --> 02:08.560
So later we can use it.

02:09.160 --> 02:12.640
It is going to be Mac address search result.

02:13.080 --> 02:14.480
So let's use Mac.

02:17.760 --> 02:18.400
Address.

02:20.600 --> 02:22.640
Search result.

02:22.840 --> 02:25.480
It is equal to something like this.

02:26.080 --> 02:26.680
And.

02:28.800 --> 02:29.080
Okay.

02:29.120 --> 02:31.560
Now I think it is installed.

02:36.000 --> 02:40.080
Um, okay, I think I don't have internet connection.

02:40.080 --> 02:40.600
No problem.

02:40.600 --> 02:41.680
I will solve that.

02:41.720 --> 02:48.440
Okay, so now we have installed the we have installed this into this variable.

02:48.440 --> 02:48.840
Okay.

02:50.160 --> 02:55.160
So the next part is to just print this very easy okay.

02:55.200 --> 02:57.480
So I just use print method here.

02:57.720 --> 02:58.120
Okay.

02:58.840 --> 03:02.400
And Mac address search result.

03:02.680 --> 03:06.400
And sometimes it return multiple values okay.

03:06.440 --> 03:12.440
For example right now here it is only returning one thing and that is the Mac address.

03:12.920 --> 03:15.240
But sometimes it is returning multiple things.

03:15.240 --> 03:19.520
So we need to specify that by using another function that is called group.

03:19.600 --> 03:21.840
And here we give the zero.

03:21.840 --> 03:25.160
So it will give you the first one or the specified by one.

03:25.160 --> 03:29.840
So it will give you the next one which is the second one okay.

03:30.920 --> 03:35.800
So we have this and let me go to Python interpreter.

03:36.120 --> 03:37.360
See if it is installed.

03:39.240 --> 03:40.840
Import re.

03:41.480 --> 03:41.640
Okay.

03:41.680 --> 03:43.040
As you see it gives me no error.

03:43.040 --> 03:44.600
That means it is installed.

03:44.600 --> 03:45.280
Very good.

03:45.840 --> 03:48.120
And is it okay.

03:48.160 --> 03:51.040
So what is the next thing we need to do right now.

03:51.040 --> 03:52.360
If I execute this.

03:52.480 --> 03:58.200
So it will give me no error and it will be executed successfully.

03:58.200 --> 04:01.800
So let's see that here.

04:02.800 --> 04:07.800
So right now I'm trying to change the Mac address for it is zero.

04:07.800 --> 04:13.800
And hitting enter providing the password which is curly and hitting enter.

04:14.400 --> 04:14.640
So.

04:16.680 --> 04:17.120
Okay.

04:18.000 --> 04:26.200
And here you see it gives me a result says cannot use string pattern on byte like object.

04:26.520 --> 04:27.640
Okay no problem.

04:27.920 --> 04:29.960
As you see here it is string.

04:29.960 --> 04:32.520
And it is saying that we cannot use this okay.

04:33.840 --> 04:34.760
On object.

04:34.960 --> 04:37.520
So it is better to change it to something else.

04:37.880 --> 04:39.600
I will be back okay.

04:46.000 --> 04:46.480
Okay.

04:46.480 --> 04:49.280
We have re here which is going to be an object.

04:49.440 --> 04:50.440
And also.

04:54.680 --> 04:56.120
Let's see the error again.

04:56.240 --> 04:58.040
What is it giving me.

04:58.400 --> 05:00.440
It is saying return this one okay.

05:00.600 --> 05:02.960
And also dot search.

05:03.480 --> 05:04.200
Oh my God.

05:04.240 --> 05:07.040
This search method must have string.

05:07.080 --> 05:07.520
Okay.

05:07.880 --> 05:12.240
Anything that it returns, anything you give to this must be string.

05:12.760 --> 05:14.970
So here as you see the first one.

05:14.970 --> 05:17.850
It is a string and this ifconfig I think it is not a string.

05:17.890 --> 05:24.610
Okay, so let's provide this as a string and change it to string str.

05:32.970 --> 05:42.210
Now let me save this and let's go back to our terminal here Re-execute this and hit enter.

05:42.570 --> 05:42.930
Okay.

05:43.370 --> 05:44.970
Now as you see here okay.

05:45.010 --> 05:48.770
The first one, it is giving me the result okay.

05:48.810 --> 05:51.770
The result for eth0 as you see that here.

05:52.330 --> 05:59.970
And then at the end it is printing only the Mac address that we are telling this to print that here.

06:00.930 --> 06:01.250
Okay.

06:01.610 --> 06:05.970
What if I try to change this for not.

06:06.010 --> 06:08.090
It is zero for low.

06:08.130 --> 06:09.770
What will be happening?

06:10.010 --> 06:10.570
Let's see.

06:12.850 --> 06:17.290
Now when I hit enter, you see that it is printing the low result here.

06:17.450 --> 06:17.890
Okay.

06:18.450 --> 06:29.450
And it is giving me that the interface is low, but but, uh, again, it is giving me this result.

06:29.490 --> 06:29.730
Why?

06:29.770 --> 06:34.850
Because the low doesn't have any Mac address, so we need to handle that here.

06:34.890 --> 06:35.610
Okay.

06:35.650 --> 06:40.490
After printing or before printing that we need to handle that using decision making.

06:40.730 --> 06:45.690
And you know how to use decision making that is using by using if and else.

06:45.930 --> 06:52.290
So here I'm going to use if Mac address source result.

06:52.650 --> 06:59.690
If it returns something true then we will be printing this one okay.

06:59.730 --> 07:01.170
In else part okay.

07:01.210 --> 07:01.850
In else part.

07:01.850 --> 07:02.690
Let's print.

07:03.090 --> 07:06.490
Could not read Mac address or something like that okay.

07:06.530 --> 07:10.090
So use else and here print that.

07:15.490 --> 07:17.170
Okay.

07:17.210 --> 07:18.570
Here just give.

07:22.650 --> 07:23.410
Uh, okay.

07:24.810 --> 07:30.570
Could not read Mac address.

07:33.290 --> 07:36.970
Now I'm going to save this and let's come back to terminal.

07:37.610 --> 07:39.130
Let's use clear.

07:42.450 --> 07:42.930
Image.

07:49.010 --> 07:49.330
Okay.

07:49.330 --> 07:51.490
Right now I'm trying to change it for lo.

07:52.130 --> 07:56.450
And you see that it is giving me could not read Mac address.

07:56.490 --> 07:56.890
Okay.

07:57.650 --> 08:04.050
And if I try to change it for eth0 that is here and hit enter.

08:04.050 --> 08:06.570
You see it is giving me the Mac address.

08:06.570 --> 08:11.330
So here we are able to read or capture the Mac address from this output.

08:11.370 --> 08:11.610
Okay.

08:11.650 --> 08:15.210
This is the Mac address for this interface.

08:15.210 --> 08:16.810
And we are handling it.

08:16.810 --> 08:17.730
We just handled it.

08:17.770 --> 08:18.490
Okay.

08:18.530 --> 08:23.130
So let's go and see how we can improve this in the next lecture.
