Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting started with a whois script. 1

Status
Not open for further replies.

fortytwo

Technical User
Apr 18, 2000
206
GB
I have been asked to write a whois script.&nbsp;&nbsp;Does anyone have any pointers?&nbsp;&nbsp;It will take a domain name without the TLD and then add a selected TLD and search for it.&nbsp;&nbsp;Anyone got any ideas? <p>fortytwo<br><a href=mailto:will@hellacool.co.uk>will@hellacool.co.uk</a><br><a href= test site</a><br>
 
OK. Does anyone have any advice on the use of<br><br>$nslookup = &quot;/user/bin/nslookup&quot;;<br>$command = &quot;$nslookup -timeout=2 -q=ns $domainname 2&gt;&1&quot;;<br>open(SHELL, &quot;$command ¦&quot;);<br><br>What does it all mean?&nbsp;&nbsp;I am stuggling here :) <p>fortytwo<br><a href=mailto:will@hellacool.co.uk>will@hellacool.co.uk</a><br><a href= test site</a><br>
 
<i>nslookup</i> - is a UNIX command to get information about boxes on a network, be it an intranet or the internet.&nbsp;&nbsp;It sends queries to a <i>domain name server</i> to get information about the servers that the domain name server knows about.&nbsp;&nbsp;There are a variety of arguments.&nbsp;&nbsp;<br>The ones you are using, <i>-timeout</i> and <i>domainname</i>, do what they sound like.&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;-<i>timeout</i> specifies how long to try to get a response before dying.<br>&nbsp;&nbsp;&nbsp;&nbsp;-<i>domainname</i> specifies the mask for the domain your are interested in.<br><br><b>So</b>, we have a UNIX command and two args for it.<br><br>Next, what does <i>open(SHELL, &quot;$command ¦&quot;);</i>&nbsp;&nbsp;do?<br>Answer - the '<b>¦</b>' char in the end of the parens is called a pipe and is a pipe.&nbsp;&nbsp;That is, the character is a pipe AND the syntax opens a 'pipe' to the UNIX command and attaches a handle to it.&nbsp;&nbsp;That means you can read from the stuff the UNIX command spits back just like it is a file.<br><br>So, your code builds the appropriate syntax to use with the <i>nslookup</i> command and then opens a <i>pipe</i> to that command so you can catch what it spits back.<br><br>Hope this helps.......
 
Thanks goBoating.&nbsp;&nbsp;It has helped.&nbsp;&nbsp;The script is coming along nicely now.<br><br>Regards<br>Will. <p>fortytwo<br><a href=mailto:will@hellacool.co.uk>will@hellacool.co.uk</a><br><a href= test site</a><br>
 
$command = &quot;$nslookup -timeout=2 -q=ns $domainname 2&gt;&1&quot;;<br>OK, I have this down to check for an authoritative answer from some nameservers.&nbsp;&nbsp;I cannot get it to return $nameservers = 1 though.&nbsp;&nbsp;I have tried to match:<br><br>Authoritative Answer<br>Authoritative Answers<br>Authoritative answers<br><br>$nslookup = &quot;/usr/local/bin/nslookup&quot;;<br>open(SHELL, &quot;$command ¦&quot;);<br>while(&lt;SHELL&gt;) {<br>#looking for authoritative nameserver<br>if (/^Authoritative Answer/) {<br>$nameservers = 1;<br>}<br>else<br>{<br>$nameservers = 0;<br>}<br>}<br>close(SHELL);<br>print &quot;$out\n&quot;;<br><br>Anyone got any ideas on this one?<br><br>Thanks.<br> <p>fortytwo<br><a href=mailto:will@hellacool.co.uk>will@hellacool.co.uk</a><br><a href= test site</a><br>
 
a little more UNIX stuff.......<br>When you use the <i>open(SHELL,&quot;$command ¦&quot;)</i>, the pipe connects to STDOUT of the command.&nbsp;&nbsp;It looks like your command has redirected STDOUT to go to somewhere else.&nbsp;&nbsp;If this is the case, then the output of <i>nslookup</i> will not make it back through the pipe.&nbsp;&nbsp;The <font color=red>&gt;</font> is the redirect operator.<br><br>You can run nslookup from the command line.&nbsp;&nbsp;Loose the <font color=red>&gt;&1</font>, run it at a prompt and see what you get back.&nbsp;&nbsp;Make sure you are using the nslookup command the way your OS expects.&nbsp;&nbsp;<br><br>I am using SunOS 5.6...when I do this...<br><b>nslookup -timeout=5 -q=ns awac.com</b><br>I get this....<br><b>Server:&nbsp;&nbsp;someserver.somewhere.com<br>Address:&nbsp;&nbsp;213.267.12.199<br><br>Non-authoritative answer:<br>awac.com nameserver = ns-1.awac.com<br>awac.com nameserver = ns-2.awac.com<br><br>Authoritative answers can be found from:<br>ns-1.awac.com internet address = 207.146.99.11<br>ns-2.awac.com internet address = 207.146.99.12<br></b><br><font color=red> the names have been changed to protect the innocent</font><br><br>Once, you are sure you are using the command correctly, migrate the command syntax into your Perl code.&nbsp;&nbsp;Drop a print in the 'while(SHELL,&quot;$command ¦&quot; { }' loop to make sure you are, in fact, getting something back.&nbsp;&nbsp;If so, what does it look like....make adjustments to your match and you're there.<br><br><br>' Hope this helps. <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
Thanks<br><br>I have managed to put a working version together (apart from the uk.com's) here:<br><br><A HREF=" TARGET="_new"> any one wants to see the script, email me.<br><br>Will <p>fortytwo<br><a href=mailto:will@hellacool.co.uk>will@hellacool.co.uk</a><br><a href= test site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top