Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello.
How can I get remote IP of a Windows 2000 Professional and store the IP in a scalar and print the IP to a .txt file (I.m using a Windows 2000 Professional)?.

Both Windows 2000 Professional has registered in a WINS database.

I know the name of the remote machine (computerA) but not the IP.

I,m using the "Net::Ping" to ping machine on the NetBIOS name.

Can I use the "Net::NBName" to get the IP?.


//Anders Andersson

Replies are listed 'Best First'.
Re: How can get remote IP of Windows OS?
by meetraz (Hermit) on Mar 01, 2004 at 03:04 UTC
    This is the way I do it.. pretty simple:

    use Socket; my $hostname = 'win2kprof'; my $addr = inet_ntoa(scalar gethostbyname($hostname)); print "ip address is $addr\n";

Re: How can get remote IP of Windows OS?
by flyingmoose (Priest) on Feb 29, 2004 at 16:20 UTC
    Is there a reason to use the Microsoft-specific WINS? I know WINS often works better when dealing with borked DNS systems, etc, but Net::DNS seems to be a more universal solution. Most likely (unless your DNS is really polluted with bad entries) using DNS instead of WINS will work for you.
Re: How can get remote IP of Windows OS?
by semio (Friar) on Feb 29, 2004 at 17:48 UTC
    Looks as though you should be ok with Net::Ping. This small example, a piece of which is provided in the perldoc, should get you started.
    #!perlenv -w use strict; use Net::Ping; if ($#ARGV < 0) { print "usage: ping.pl <hostname>"; exit; } my $host = $ARGV[0]; my $file = "IPAddress.txt"; open (FILE, ">$file"); my $p = Net::Ping->new(); my ($ret, $duration, $ip) = $p->ping($host, 5.5); print "$host [ip: $ip] is alive.\n" if $p->ping($host); $p->close(); print FILE $ip; close(FILE);
    cheers