Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
M
myfirstproject
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
aghead.asaad
myfirstproject
Commits
1f1009e7
Commit
1f1009e7
authored
Jun 29, 2024
by
aghead.asaad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exercise3
parent
0c71dc00
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
exercise3
exercise3
+23
-0
No files found.
exercise3
0 → 100755
View file @
1f1009e7
#!/bin/bash
# alive2.sh
# Checks to see if a range of IP addresses are alive
# Input should be in the format alive2.sh 192.168.1.7-192.168.1.123
# Validate the input format
if
[[
$1
=
~ ^[0-9]+
\.
[
0-9]+
\.
[
0-9]+
\.
[
0-9]+-[0-9]+
\.
[
0-9]+
\.
[
0-9]+
\.
[
0-9]+
$
]]
;
then
start
=
$(
echo
$1
|
cut
-d
'-'
-f1
|
cut
-d
'.'
-f4
)
end
=
$(
echo
$1
|
cut
-d
'-'
-f2
|
cut
-d
'.'
-f4
)
# Iterate through IP addresses
for
((
n
=
start
;
n<
=
end
;
n++
))
;
do
host
=
$(
echo
$1
|
cut
-d
'-'
-f1
|
cut
-d
'.'
-f1-3
)
.
$n
ping
-c2
$host
&> /dev/null
if
[
$?
=
0
]
;
then
echo
"
$host
is UP"
else
echo
"
$host
is DOWN"
fi
done
else
echo
"Invalid input format. Please use the format alive2.sh 192.168.1.7-192.168.1.123"
fi
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment