Skip to content

Instantly share code, notes, and snippets.

@danielmacuare
Last active December 14, 2019 17:57
Show Gist options
  • Save danielmacuare/10e5e68b6e8dbf658362566aa928e912 to your computer and use it in GitHub Desktop.
Save danielmacuare/10e5e68b6e8dbf658362566aa928e912 to your computer and use it in GitHub Desktop.
Bash script to resolve names or IPs
#!/bin/bash
# Function that will expect a list of arguments from the cli and will resolve them using the host command.
# It will return the dns records or Ips on stdout
# Example bash hosts_cmd.sh 10.176.148.12 10.176.148.193 10.176.152.63 10.176.152.64 10.176.152.65 10.176.152.66 10.176.152.67 10.176.152.68 10.176.152.69 10.176.152.70 10.176.152.71 10.176.152.72
#USAGE
# bash hosts_cmd.sh 10.195.129.22 10.195.129.23 10.185.129.62 10.185.129.63
light_green_bold="\033[1;92;49m"
red_bold="\033[1;31;49m"
blue_bold="\033[1;34;49m"
normal="\033[0m"
resolver(){
for ip_names in "$@"; do
output=$(host $ip_names | awk '{print $5}' | sed 's/\.$//g')
printf "$blue_bold $ip_names $normal-$light_green_bold $output $normal\n"
done
}
resolver $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment