Bash

#!/bin/bash## Note: Only works with bash 3.x or 4.x+ #### source: http://www.cyberciti.biz/tips/unix-linux-bash-shell-script-wrapper-examples.html# Instead of using /bin/ping in order to get real ‘ping’, you can use the command shell bultiin:# command ping --> Run command with arguments ignoring any shell function named command. # http://ss64.com/bash/command.html_getdomainnameonly(){localh="$1"localf="${h,,}"# remove protocol part of hostnamef="${f#http://}"f="${f#https://}"f="${f#ftp://}"f="${f#scp://}"f="${f#scp://}"f="${f#sftp://}"# remove username and/or username:password part of hostnamef="${f#*:*@}"f="${f#*@}"# remove all /foo/xyz.html*f=${f%%/*}# show domain name onlyecho"$f"}ping(){localarray=([email protected])# get all args in an arraylocallen=${#array[@]}# find the length of an arraylocalhost=${array[$len-1]}# get the last arglocalargs=${array[@]:0:$len-1}# get all args before the last arg in [email protected] in an array#local _ping="/bin/ping"localc=$(_getdomainnameonly "$host")["$t" !="$c"]&&echo"Sending ICMP ECHO_REQUEST to \"$c\"..."# pass args and host#$_ping $args $c # improving scriptcommand ping $args$c}host(){localarray=([email protected])locallen=${#array[@]}localhost=${array[$len-1]}localargs=${array[@]:0:$len-1}#local _host="/usr/bin/host"localc=$(_getdomainnameonly "$host")["$t" !="$c"]&&echo"Performing DNS lookups for \"$c\"..."#$_host $args $ccommand host $args$c}