#!/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