summaryrefslogtreecommitdiff
path: root/bin/problem-7.sh
blob: 8ec6e0c2eafd6a160340c6f92a920841606ccc28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/sh

if [ $# -eq 0 ]; then
  echo "error: a hostname is required" >&2
  exit 1
fi

check() {
  destination="$1"
  host=$(host "$1" | grep 'has address')
  ip=$(echo "$host" | cut -d' ' -f4)
  ping -c1 $ip > /dev/null 2>&1

  if [ $? -eq 0 ]; then
    echo "$1" is on the network
  else
    echo "$1" is NOT on the network
  fi
}

for i in "$@"; do
  check "$i"
done
exit 0