Advertisement
voyeg3r

ping-wrapper

Dec 19th, 2015
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.22 KB | None | 0 0
  1. # PING WRAPPER ------------------------------------------------
  2. # source: http://www.cyberciti.biz/tips/unix-linux-bash-shell-script-wrapper-examples.html
  3. _getdomainnameonly(){
  4.     # Name: _getdomainnameonly
  5.     # Arg: Url/domain/ip
  6.     # Returns: Only domain name
  7.     # Purpose: Get domain name and remove protocol part, username:password and other parts from url
  8.     # get url
  9.     local h="$1"
  10.     # upper to lowercase
  11.     local f="${h:l}"
  12.     # remove protocol part of hostname
  13.     f="${f#http://}"
  14.     f="${f#https://}"
  15.     f="${f#ftp://}"
  16.     f="${f#scp://}"
  17.     f="${f#scp://}"
  18.     f="${f#sftp://}"
  19.     # Remove username and/or username:password part of hostname
  20.     f="${f#*:*@}"
  21.     f="${f#*@}"
  22.     # remove all /foo/xyz.html*
  23.     f=${f%%/*}
  24.     # show domain name only
  25.     echo "$f"
  26. }
  27.  
  28. # Name: ping() wrapper
  29. # Arg: url/domain/ip
  30. # Purpose: Send ping request to domain by removing urls, protocol, username:pass using system /usr/bin/ping
  31. ping(){
  32.     local t="$1"
  33.     local _ping="/usr/bin/ping"
  34.     local c=$(_getdomainnameonly "$t")
  35.     [ "$t" != "$c" ] && echo "Sending ICMP ECHO_REQUEST to \"$c\"..."
  36.     $_ping -n -c 4 -i 0.2 -W1 $c
  37. }
  38. # END PING WRAPPER ------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement