#!/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(){
    local h="$1"
    local f="${h,,}"
    # remove protocol part of hostname
        f="${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 hostname
    f="${f#*:*@}"
    f="${f#*@}"
    # remove all /foo/xyz.html*
    f=${f%%/*}
    # show domain name only
    echo "$f"
}
 
ping(){
    local array=( [email protected] )          # get all args in an array
    local len=${#array[@]}          # find the length of an array
    local host=${array[$len-1]}     # get the last arg
    local args=${array[@]:0:$len-1} # get all args before the last arg in [email protected] in an array
    #local _ping="/bin/ping"
    local c=$(_getdomainnameonly "$host")
    [ "$t" != "$c" ] && echo "Sending ICMP ECHO_REQUEST to \"$c\"..."
    # pass args and host
    #$_ping $args $c # improving script
    command ping $args $c
}
 
host(){
    local array=( [email protected] )
    local len=${#array[@]}
    local host=${array[$len-1]}
    local args=${array[@]:0:$len-1}
    #local _host="/usr/bin/host"
    local c=$(_getdomainnameonly "$host")
    [ "$t" != "$c" ] && echo "Performing DNS lookups for \"$c\"..."
    #$_host $args $c
    command host $args $c
}