host- this command can be used to get the IP address of a domain
whois- useful in retrieving details on a given IP address
What we do here is to transfer the domain name to host command and then pass its output to whois information server.Pipelining '|' is used to pass the value(its the fundamentals of shell scripting and Unix).
shell scripting is used to make the work easier with using loops and variables.
So, to do all of this all you wants is to make a shell script and run it.
make a .sh file and copy the following lines to it
vi dnsinfo.sh
#Edited Author-chandpriyankara@engineering.com @ www.chandpriyankara.tk
#Read params
_domain=$@
# if no param URLs then echo a message and exit
[ $# -eq 0 ] &&
{
echo "Usage: $0 example1.com example2.net ....";
exit 1;
}
#iterate through all the given domain names
for dom in $_domain
do
#get the IP address of the domain name through famous shell string operations
_ipaddress=$(host $dom | grep 'has add' | head -1 | awk '{ print $4}')
[ "$_ipaddress" == "" ] &&
{
echo "Error: $dom is not valid domain or dns error. Check your firewall settings also.";
continue;
}
echo "Getting information for domain: $dom [ $_ipaddress ]..."
# retrieve the informations strating with the selected details
whois "$_ipaddress" | egrep -w 'OrgName:|City:|State:|Country:|OriginAS:|NetRange:'
echo ""
done
Then assign the file executable file attributes
chmod 755 dnsinfo.sh
Now its all about what who's information you wants..
Here is a test run on www.google.lk
go to the path where the .sh located and type this:
./dnsinfo.sh www.google.lk www.yahoo.com www.facebook.com | less
Notice that i have added another command to the script here.
By removing: [
| egrep -w 'OrgName:|City:|State:|Country:|OriginAS:|NetRange:'] you can show all the information without filtering
No comments:
Post a Comment