1
00:00:01,150 --> 00:00:07,120
OK so we have discussed theory so let's write some script grade file.

2
00:00:07,230 --> 00:00:15,130
I pleaded as age and on the first line start vade siobhán been Bash.

3
00:00:16,890 --> 00:00:22,940
Now your target is to provide one word or a sentence

4
00:00:27,460 --> 00:00:29,360
as an argument.

5
00:00:31,340 --> 00:00:31,970
To discrete

6
00:00:35,150 --> 00:00:36,830
if in that sentence

7
00:00:40,320 --> 00:00:49,160
there will be IP address.

8
00:00:49,360 --> 00:00:50,320
Find out

9
00:00:56,940 --> 00:00:58,620
if that IP address

10
00:01:01,950 --> 00:01:04,520
is reachable or not.

11
00:01:07,620 --> 00:01:08,730
That means dead.

12
00:01:08,760 --> 00:01:12,460
You need to create a script which takes 1 hour of Blooms-End.

13
00:01:12,630 --> 00:01:20,550
And if that argument is some very present IP address you need to find out if that IP address is reachable

14
00:01:20,640 --> 00:01:21,240
or not

15
00:01:24,270 --> 00:01:26,000
as need exactly one argument.

16
00:01:26,010 --> 00:01:29,380
We can start with that argument check.

17
00:01:29,430 --> 00:01:42,630
So if they are sign Hesh which means number of arguments if it is not equal to them then we can print

18
00:01:44,360 --> 00:01:51,760
ICO provide exactly one argument.

19
00:01:53,610 --> 00:01:54,210
E.g.

20
00:01:56,880 --> 00:02:08,810
the lot of Sanzio which means our escape name and somebody who meant we can also exit with stutterers

21
00:02:08,820 --> 00:02:15,230
of Amina.

22
00:02:15,310 --> 00:02:23,560
Now we can assign first argument to variable Cold War One

23
00:02:27,310 --> 00:02:36,210
and we can now write a regular expression for IP address.

24
00:02:36,230 --> 00:02:39,530
I will also do some comment here.

25
00:02:40,400 --> 00:02:42,950
IP address rhetoric's

26
00:02:46,580 --> 00:02:55,090
So we know that IP address has four part of digits divided by default.

27
00:02:55,440 --> 00:03:03,410
And I think it would be best to write some example here some example of IP address

28
00:03:06,750 --> 00:03:14,230
that is good to know that each part of that IP address can have one up to three digits and digits only.

29
00:03:14,260 --> 00:03:21,630
So first part in the first part we have range 0 2 9 and it will be repeated one to three times.

30
00:03:21,700 --> 00:03:25,970
So I will put one commissary into curly brackets.

31
00:03:25,970 --> 00:03:32,020
Then we have a dot but dot is a special character which means any character so we need to use backslash

32
00:03:32,350 --> 00:03:33,270
before that.

33
00:03:33,370 --> 00:03:41,460
And by that we are telling that this is only Klesko normal dot without any special effects.

34
00:03:41,470 --> 00:03:51,350
Now we can continue the second part which is same as the first one and the same you can do also for

35
00:03:51,460 --> 00:03:52,030
search.

36
00:03:52,060 --> 00:03:52,480
But

37
00:03:56,090 --> 00:04:01,070
so we're in 0 9 and then repeat one to three times

38
00:04:04,200 --> 00:04:05,920
for the fourth part.

39
00:04:05,940 --> 00:04:13,940
We can also instead of orange in square brackets use special character class gold digit.

40
00:04:14,220 --> 00:04:29,580
Discuss with prisons any number and we will also repeat these digit one to three times.

41
00:04:29,940 --> 00:04:41,060
And now we can finally do some regs check to see if indeed argument is IP address provided or not.

42
00:04:41,130 --> 00:04:47,130
So right if an inside square brackets of right where one equals sign

43
00:04:52,420 --> 00:04:54,420
and after equal sign deal done

44
00:04:57,140 --> 00:05:02,730
and our variable that regular expression.

45
00:05:03,200 --> 00:05:07,890
Now we are basically asking if IP address is found and if yes do something.

46
00:05:07,940 --> 00:05:12,750
But that would be to ask immediately if IP is not found.

47
00:05:13,850 --> 00:05:16,170
And in that case it's in disarray.

48
00:05:16,190 --> 00:05:21,870
So for that reason I am putting exclamation mark before square brackets.

49
00:05:22,160 --> 00:05:26,520
Basically I'm doing negation.

50
00:05:26,700 --> 00:05:33,240
So if there is no IP address found we can bring the users ICO.

51
00:05:33,330 --> 00:05:35,860
No IP address provided.

52
00:05:36,210 --> 00:05:41,010
And we can also exit the status to

53
00:05:44,990 --> 00:05:47,440
now if the script won't be exited here.

54
00:05:47,450 --> 00:05:55,760
We are sure that some IP address was found and would be good to store it into variable for example IP

55
00:05:57,500 --> 00:06:01,680
for that we will use for that IP address.

56
00:06:01,760 --> 00:06:13,370
We will use beshe rematch 0 do remember do remember understory I told you about that as they're very

57
00:06:13,480 --> 00:06:22,350
much zero Michie's all those regs we have to specify and be careful how you ride bansuri much as there

58
00:06:22,350 --> 00:06:24,650
are bought Kirtley and square brackets.

59
00:06:26,610 --> 00:06:32,160
Now we need to find if that IP address is reachable or not.

60
00:06:32,490 --> 00:06:33,860
How to do that.

61
00:06:34,200 --> 00:06:36,320
Beeville use Bing.

62
00:06:36,320 --> 00:06:38,360
Come on.

63
00:06:38,430 --> 00:06:45,790
I will firstly write some comment find if IP address is reachable

64
00:06:50,810 --> 00:06:57,350
or not and on the next line we can do basic common

65
00:07:06,210 --> 00:07:10,890
vowed I have here read text which means that something is wrong.

66
00:07:11,280 --> 00:07:16,870
And yes I have mistake in if statement.

67
00:07:16,890 --> 00:07:25,380
I didn't use dollar sign before the rebel so I will just fix it now and we can continue with Bing.

68
00:07:25,410 --> 00:07:34,710
Come on we will ping four times our IP address.

69
00:07:34,890 --> 00:07:36,920
So I really will spin the barometer.

70
00:07:36,980 --> 00:07:37,730
See.

71
00:07:38,000 --> 00:07:42,400
And that barometer C means how many buckets do we want to send

72
00:07:45,250 --> 00:07:46,310
now.

73
00:07:46,770 --> 00:07:58,400
If that ping command was successful vivo assign to variables that those some the message.

74
00:07:58,820 --> 00:08:13,410
So if it is that is zero then we assign it to status variable message alive.

75
00:08:13,780 --> 00:08:24,430
And if ping was not successful we will assign it to that those message that are not reachable

76
00:08:29,780 --> 00:08:34,120
and to now we can print it go

77
00:08:38,320 --> 00:08:40,280
I'd be fine.

78
00:08:40,390 --> 00:08:53,180
And if you specify our IP address us are assigned IP and in parentheses we put our status as the status

79
00:08:53,240 --> 00:08:54,590
of that IP address

80
00:08:57,460 --> 00:08:59,440
we can safely descript

81
00:09:02,440 --> 00:09:11,120
and Grant executive permission we can descript to create one and

82
00:09:19,080 --> 00:09:21,900
all I forgot to properly call descript.

83
00:09:21,900 --> 00:09:23,370
So once they Murra

84
00:09:30,560 --> 00:09:35,630
integrate no IP address provided it works perfectly.

85
00:09:35,780 --> 00:09:40,420
I can try now without any arguments and great.

86
00:09:40,460 --> 00:09:44,800
I have a message to provide exactly one argument.

87
00:09:44,840 --> 00:09:51,110
Now I can try with two arguments and we have to provide exactly one arguments.

88
00:09:51,200 --> 00:09:54,970
Great.

89
00:09:55,130 --> 00:10:06,690
Now let's put as an argument you are a computer localhost IP address and we see the pink output and

90
00:10:06,900 --> 00:10:12,070
at the end we have message IP from the stutterers alive.

91
00:10:12,170 --> 00:10:16,170
Great but I don't like to see that pink output.

92
00:10:16,210 --> 00:10:18,290
Last sentence will be enough.

93
00:10:18,360 --> 00:10:28,920
So I think that we can go back to our script and we will redirect standard output display to screen

94
00:10:29,160 --> 00:10:30,120
to Dev-Null.

95
00:10:30,300 --> 00:10:41,820
So after being command right to him which means standard output and every day the NSA agreed to Dev-Null

96
00:10:45,300 --> 00:10:47,890
thanks to that we won't see any big output.

97
00:10:48,030 --> 00:10:50,120
So let's try this out.

98
00:10:51,150 --> 00:10:59,030
But now as an argument I value some sentence which can represent for example one line from a companion

99
00:10:59,030 --> 00:11:01,840
document with IP addresses description.

100
00:11:02,220 --> 00:11:08,040
And of course if you need to find out if IP address is present here and if it is reachable

101
00:11:11,720 --> 00:11:16,050
so I have specified songs and then with IP address in it

102
00:11:19,710 --> 00:11:29,310
and we can round it and grade b c i be found and it is alive.

103
00:11:29,820 --> 00:11:39,960
So now we can change the sentence to something else and mainly change the idea that has to be not reachable.

104
00:11:52,860 --> 00:11:54,280
Now you need to wait.

105
00:11:54,870 --> 00:11:56,340
And as IP was found.

106
00:11:56,370 --> 00:12:01,630
But it but it is dead not reachable.

107
00:12:01,740 --> 00:12:11,410
Maybe you don't like to wait so long for Pinga to spawn so you can change big barometer of see and then

108
00:12:11,410 --> 00:12:12,720
running again.

109
00:12:15,970 --> 00:12:21,040
So after a few second we should see the exact same response.

110
00:12:21,880 --> 00:12:24,260
That IP was found and it is dead.

111
00:12:25,420 --> 00:12:31,480
So we have now learned how to use regular expressions in our scripts.

112
00:12:31,780 --> 00:12:34,480
And I will wait for you in next lecture.
