Skip to content

Instantly share code, notes, and snippets.

@davidgao
Created July 1, 2013 06:37
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 davidgao/5898785 to your computer and use it in GitHub Desktop.
Save davidgao/5898785 to your computer and use it in GitHub Desktop.
just a dirty hosts refreshing script
#! /bin/bash
#skip empty or comment lines
function host_filter {
while read line; do
echo $line | grep -Ev "^($|#)"
done
}
#pick second part as hostname
function host_pickname {
while read entry; do
echo $entry | awk '{print $2}';
done
}
#really perform lookup and tidy up
function host_lookup {
while read name; do
#for ipv6
#add=`nslookup -q=aaaa $name | grep AAAA | awk '{print $5}'`
#for ipv4
add=`nslookup $name | grep "Address" | grep -v "#" | head -n1 | awk '{print $2}'`
echo $add $name
done
}
host_filter | host_pickname | host_lookup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment