I need help with...<various>


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I need help with...<various>
# 8  
Old 08-23-2008
era:

I THINK 193.0.0.236 is the IP OF the nameserver, not the A record ON the nameserver for example.com:

ping -c 1 b.iana-servers.net | grep '64 bytes' && dig +short @b.iana-servers.net example.com
64 bytes from b.iana-servers.net (193.0.0.236): icmp_seq=1 ttl=51 time=99.8 ms
208.77.188.166
# 9  
Old 08-23-2008
Now I am confused (... or you are :-)

example.com has two name servers. Their names are b.iana-servers.net and a.iana-servers.net. These are the servers which will tell you the IP address of example.com, should you ever ask for it. The way I understood your question, the IP addresses of the name servers is what you want your script to print.

So, given the input example.com, it should print the IP addresses of a.iana.servers.net and b.iana-servers.net

Or, given the input unix.com, it should look up the name servers for unix.com (ns1.sitesolutions.com through ns4.sitesolutions.com) and print their IP addresses.

Did I not understand you correctly? If so, can you rephrase your question?
# 10  
Old 08-23-2008
era:

I just want to know the A record value for example.com that the nameservers have.

HTH.
# 11  
Old 08-23-2008
So you don't care at all about what the nameservers are? Or you want to query all the authoritative name servers in turn? In the former case, host -t a example.com is all you need. In the latter case, what you have (sort of) makes sense, except your version of the script fails to specify which name server to use (but obviously you know how to use dig @server to do that, or you can use host example.com b.iana-servers.net to specify b.i-s.n as the name server to use; but dig is certainly more scripter-friendly).

Code:
#!/bin/sh
host=$1
dig +short ns $host |
while read nameserver; do
  dig +short @$nameserver $host | sed "s/^/IP for $host at $nameserver is /"
done

It's not a one-liner unless your lines have fractal dimensions but I hope that wasn't strictly a requirement.

Last edited by era; 08-23-2008 at 05:37 PM.. Reason: Note absence of @server param; add code snippet
# 12  
Old 08-23-2008
Using almost every trick in the book, I got it down to the following maintainability nightmare.

Code:
d="dig +short"; $d ns $1 | xargs -i sh -c "$d @{} $1 | sed 's/^/IP for $1 at {} is /'"

I bet radoulov could still improve on that.

Last edited by era; 08-23-2008 at 05:44 PM.. Reason: Summon radoulov
# 13  
Old 08-23-2008
Era:

Don't make a project out of it. You're starting to sound a little OCD'ish over there. Smilie
# 14  
Old 08-23-2008
It even works on my Ubuntu 8.04 platform. I'm in heaven.
I am struggling with echo'ing "IP for scallyroottest.com is" +"at"
from this command:
host -t ns example.com | while read dom ns server; do dig +short $dom; done but managed this poor example of a coding attempt using the example:

host -t ns example.com | while read dom ns server ; do echo "IP for" $dom "is" "<IP>" "at"; done
but it's still missing the do dig routine.

Not sure if/how it can be done. Can you have >1 do ; done routine?

Short of any clear answers, I am on my way to some serious homework. Smilie

Thanks everyone who pitched in with support....
Login or Register to Ask a Question

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