Nathaniel Wert wrote:
>
> I am trying to make a feable attempt at parsing a nslookup call. All I actually
>want is the IP address. So I figured I would do the following:
>
> $ticker = 0;
> foreach $_ (`nslookup $nodename`) {
> $_ = $out[$ticker];
> $ticker++;
> }
>
> print $out[0];
>
> I am getting a uninitalized error for $out[0]. Three questions:
>
> 1) What am I doing wrong with this? I am not sure why this is not working.
> 2) I orginally thought that $_ was a array value and I could just do a "$_ = @foo".
>I have found that I am mistaken. Is there any way to get the output into an array
>from by line of input?
> 3) General suggestions on an easier way to do this. Is there an actual function
>that will do an nslookup or get the ip address of a nodename?
Maybe this will give you some ideas:
# perl -le'$host = "google.com"; ($ip) = `nslookup $host` =~
/Name:\s+$host\s+Address(?:es)?:\s+(.+)/; print $ip'
216.239.33.100, 216.239.35.100, 216.239.37.100, 216.239.39.100
# perl -le'$host = "groups.google.com"; ($ip) = `nslookup $host` =~
/Name:\s+$host\s+Address(?:es)?:\s+(.+)/; print $ip'
216.239.35.119
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]