Skip to content

Instantly share code, notes, and snippets.

@jasonwbarnett
Created December 4, 2014 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonwbarnett/89554dd63e90694f40a3 to your computer and use it in GitHub Desktop.
Save jasonwbarnett/89554dd63e90694f40a3 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Note: Works with bash 4.x and above only #
# STOLEN FROM: http://www.cyberciti.biz/tips/unix-linux-bash-shell-script-wrapper-examples.html
# curl -I http://cyberciti.biz/
# ping -v -c 2 !!:2
# host -t aaaa !!:4
# host -t mx !!:3
# host -t a ftp://nixcraft.com/
# host -a ftp://nixcraft.com/
# ping 8.8.8.8
# host 8.8.8.8
_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=( $@ ) # 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 $@ 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
}
host(){
local array=( $@ )
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment