-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPing IP Addresses.sh
More file actions
54 lines (46 loc) · 1009 Bytes
/
Copy pathPing IP Addresses.sh
File metadata and controls
54 lines (46 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/env bash
# Bash script to ping a list of IP addresses from an input file and output the results to screen
# Usage: ./pingips.sh <inputfile>
# Check if input file is provided
if [ $# -eq 0 ]
then
echo "No input file provided"
echo "Usage: ./pingips.sh <inputfile>"
exit 1
fi
# Check if input file exists
if [ ! -f $1 ]
then
echo "Input file does not exist"
exit 1
fi
# Read input file line by line
while read line
do
# Check if line is empty
if [ -z "$line" ]
then
continue
fi
# Check if line is a comment
if [[ $line == \#* ]]
then
continue
fi
# Check if line is a valid IP address
if [[ $line =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]
then
# Ping IP address
ping -c 1 $line > /dev/null 2>&1
# Check if ping was successful
if [ $? -eq 0 ]
then
echo "$line is up"
else
echo "$line is down"
fi
else
echo "$line is not a valid IP address"
fi
done < $1
exit 0