I need help with...<various>


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I need help with...<various>
# 1  
Old 08-22-2008
Question I need help with...<various>

Hello:

I am trying to come up with a BASH 1-liner (I can't use perl or php scripts, don't ask) to grab the nameservers from a host -t ns <domain> command.

Here's what I have and it's as far as I can get:

host -t ns scallyrootest.com | awk '{print $4}' | sort
ns41.hostforweb.net.
ns42.hostforweb.net.

What I'd love to have is:
IP for scallyroottest.com is <IP> at ns41.hostforweb.net.
IP for scallyroottest.com is <IP> at ns42.hostforweb.net.

by running the 1-liner on mostly CentOS platforms

Please and thank you for your time.
# 2  
Old 08-22-2008
if might be a start:

Code:
host -t A -v somedomain.com | grep "ANSWER SECTION" -A 2 | grep "A" | grep -v ";;" ; host -t A -v somedomain.com | grep "AUTHORITY SECTION" -A 2 | grep -v ";;"

outputs:

Code:
somedomain.com.        3095    IN      A       xxx.xxx.xxx.xxx
somedomain.com.        3095    IN      NS      ns23.domaincontrol.com.
somedomain.com.        3095    IN      NS      ns24.domaincontrol.com.

# 3  
Old 08-23-2008
All I get from that is:
scallyrootest.com. 14400 IN A 216.246.31.81
# 4  
Old 08-23-2008
There are different versions of host so that might be the explanation. The idea is workable, though; get the verbose (debugging) output and parse out the fields you want. But in any case, to get the name and IP address of the name servers, you will need multiple queries -- one to get the names of the name servers, and another to look up their IP addresses. (Some sites put raw IP addresses in the NS records but this is strongly discouraged.)

I think Ikon misunderstood your question, perhaps because the output format you are suggesting is somewhat misleading (perhaps it should mention that these are the IP addresses of the name servers). The pipeline could be simplified a bit but the request of A records instead of NS records is wrong anyway.

Here's what my version of host prints:

Code:
vnix$ host -t ns example.com
example.com             NS      a.iana-servers.net
example.com             NS      b.iana-servers.net

So by taking the third field from that and querying for its address, we get the name server IP addresses:

Code:
host -t ns example.com | while read dom ns server; do host -t a $server; done

Dressing it up into the format you want is left as an exercise; it can be done along the same lines.

PS. Please try to think up a helpful thread topic title next time.

Last edited by era; 08-23-2008 at 12:00 PM..
# 5  
Old 08-23-2008
era:

thanks! I will use a more descriptive topic line next time.
# 6  
Old 08-23-2008
era:

coreutils-5.2.1-31.7 FWIW... Smilie

host -t ns example.com | while read dom ns server; do dig +short $dom; done
gives me:
208.77.188.166
208.77.188.166

and checking the data because we always do...

dig +short @b.iana-servers.net example.com
208.77.188.166
dig +short @a.iana-servers.net example.com
208.77.188.166

I still have work to do: "Dressing it up into the format you want is left as an exercise" Smilie

Thank you VERY much!
# 7  
Old 08-23-2008
I think you're getting the wrong result somehow; at least for me, b.iana-servers.net is 193.0.0.236 -- you're querying for $dom which is wrong, you should be querying for $server, but there can be other complications, too.

dig and host are not part of coreutils; on Ubuntu, at least, they're in the dnsutils and host packages, respectively, and there's also a separate bind9-host package which I believe contains a different version of host (hence, different output formats; originally host was also part of the dnsutils package, but many people wanted the Bind version, so they split it out).

Last edited by era; 08-23-2008 at 02:11 PM.. Reason: Observe that $dom should be $server
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question