-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreachdomain
executable file
·41 lines (34 loc) · 925 Bytes
/
reachdomain
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
#!/bin/sh
help() {
echo
echo "Checks if a specific site/domain is available"
echo
echo "Options:"
echo "-d <domain> A domain to ping / curl to check if it is available. Default: google.com"
echo "-v Verbose mode"
echo
}
[ "$1" = "--help" ] && help && exit
DOMAIN="google.com"
while getopts d:c:vh arg; do
case ${arg} in
d) DOMAIN=${OPTARG} ;;
v) VERBOSE=1 ;;
h) help && exit ;;
*) help && exit 1 ;;
esac
done
[ -z "$DOMAIN" ] && help && exit 1
if ping -c 4 "$DOMAIN" > /dev/null 2>&1; then
SUCCESS=1
else
[ -n "$VERBOSE" ] && echo "Ping failed, trying again with curl in case pings are blocked"
curl -s "$DOMAIN" > /dev/null && SUCCESS=1
fi
if [ -n "$SUCCESS" ]; then
[ -n "$VERBOSE" ] && echo "Successfully reached domain $DOMAIN"
exit 0
else
[ -n "$VERBOSE" ] && echo "Domain $DOMAIN is unreachable"
exit 1
fi