Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Problem with Win32::PingICMP and Win32::API

by as :) (Novice)
on Feb 07, 2005 at 06:30 UTC ( [id://428581]=perlquestion: print w/replies, xml ) Need Help??

as :) has asked for the wisdom of the Perl Monks concerning the following question:

Hi, In the following code I am using the Win32::PingICMP module to ping IP Addresses and print the roundtrip times. However, when I run the code I get the following error: Can't locate loadable object for module Win32::API in @INC <@INC contains: c:/Perl/lib/ c:/Perl/site/lib/.> at c:/Perl/site/lib/Win32/PingICMP.pm line 16. BEGIN failed -- compilation aborted at c:/Perl/site/lib/Win32/PingICMP.pm line 16. I have saved all the appropriate modules in the right directories as well. I would greatly appreciate it if someone could help me out here. Thanks. A.
#!/usr/local/bin/perl use strict; use Win32::ODBC; # Enables ODBC database connectivity use Win32::PingICMP; my $dsn = "postdev"; my $user = "archnas"; my $password = "something"; # Get all process related data from the database # Declare Variables my $rc; my $sql; my @ip; # Open ODBC session to database my($odbc_session) = new Win32::ODBC("dsn=$dsn; uid=$user; pwd=$passwor +d;") or die "Error connecting to $dsn\n"; # SQL $sql = " select DWH_LAN_IP FROM DAPO_CPCT_MGMT.DWH_Ntwk_Adr WHERE DWH_Ping_Flg = 'Y' "; # Submit SQL $rc = $odbc_session->Sql("$sql"); # Check for SQL errors if(defined $rc) { my $sql_error = $odbc_session->Error; my @sql_error = split /([-\[\]"])/,$sql_error; print "$sql\n"; print "SQL error: @sql_error[4,-2]\n"; exit; } # Retrieve answerset while($odbc_session->FetchRow()) { # Stores each IP Address in the @ip. my $ip_add = $odbc_session->Data(); #print "$ip_add\n"; push @ip, $ip_add; # Pushes each IP Address in the @ip to the top. + } print map {"$_\n"} @ip; my $p = Win32::PingICMP->new(); foreach (@ip) {my $ping = $p->ping($_, 5); if ($ping == 1){ $rtime = $p->details->{roundtriptime}; } else {$rtime = 0;} print "ping of $_ took $rtime ms\n"; } $p->close();

Replies are listed 'Best First'.
Re: Problem with Win32::PingICMP and Win32::API
by holli (Abbot) on Feb 07, 2005 at 07:48 UTC
    Well, it means that your installation of the Win32Win32::API-module is corrupt. Under windows, "loadable objects" are .dll-files that ship with your module. They have to be in "../perl/site/lib/auto/Module/Module.dll". I guess your Win32.dll Api.dll is missing.

    holli, /regexed monk/
      Hi, Thanks to all those who helped my try and solve my problem. I still cant seem to get it working because i cant install the Win32::API correctly (i think it's because of the firewall).
      Any ways, i am trying to ping a network and print the output to a file and then insert the results into a database. I have modified the script to do it without the Win32::API module, but i have the following error. sorry i am new to perl and this forum. i get the following error: use of uninitialised value in concatenation (.) or string line 73.
      #!/usr/local/bin/perl use strict; use Win32::ODBC; # Enables ODBC database connectivity my $dsn = "postdev"; my $user = "archnas"; my $password = "something"; # Get all process related data from the database # Declare Variables my $rc; my $sql; my @ip; my $file100 = "c:/temp/ping100.log"; my $file200 = "c:/temp/ping200.log"; # Open ODBC session to database my($odbc_session) = new Win32::ODBC("dsn=$dsn; uid=$user; pwd=$passwor +d;") or die "Error connecting to $dsn\n"; # SQL $sql = " select DWH_LAN_IP FROM DAPO_CPCT_MGMT.DWH_Ntwk_Adr WHERE DWH_Ping_Flg = 'Y' "; # Submit SQL $rc = $odbc_session->Sql("$sql"); # Check for SQL errors if(defined $rc) { my $sql_error = $odbc_session->Error; my @sql_error = split /([-\[\]"])/,$sql_error; print "$sql\n"; print "SQL error: @sql_error[4,-2]\n"; exit; } # Retrieve answerset while($odbc_session->FetchRow()) { # Stores each IP Address in the @ip. my $ip_add = $odbc_session->Data(); #print "$ip_add\n"; push @ip, $ip_add; # Pushes each IP Address in the @ip to the top. + } foreach (@ip) { my $cmd1 = "ping -n 4 -l 100 $_> $file100"; # Ping cou +nt, interval and packetsize of 100 for the IP Address. Read out to lo +g file. print "$cmd1\n"; system ($cmd1); my $cmd2 = "ping -n 4 -l 200 $_> $file200"; # Ping count, inte +rval and packetsize of 200 for the IP Address. Read out ot log file. system ($cmd2); open(FILE100, "$file100") || die "Could not open file $file100:$!\ +n"; my @file100 = <FILE100>; close(FILE100); open(FILE200, "$file200") || die "Could not open file $file200:$!\ +n"; my @file200 = <FILE200>; close(FILE200); print "$file100[9]\n $file100[11]\n"; print "$file200[9]\n $file200[11]\n"; #file100 is the variable holding the values to match on. $file100[9] =~ m/(^.*Sent\s=\s)(.*?)(\s,Received\s=\s)(.+?)(\s,Lost\s= +\s)(.??)(\s.*$)/; my $sent = $2; my $received = $4; my $lost = $6; print "$sent, $received, $lost\n"; #$file100[9] =~ m/(^.*Sent\s=\s)(.*?)(,.*)/; #print ";$1;, ;$2;\n"; #$file100[11]=~ m/^.*Minimum\s=\s(.*)\s,Maximum\s=\s(.*)\s,Average\s=\ +s(.*)\s.*$/; #my $min = $1; #my $max = $2; #my $avg = $3; #print "$min, $max, $avg\n"; exit; }
Re: Problem with Win32::PingICMP and Win32::API
by guha (Priest) on Feb 07, 2005 at 07:48 UTC
      at c:/Perl/site/lib/Win32/PingICMP.pm line 16:
      use Win32::API;
      holli, /regexed monk/

      Yeah, you're right. I should have written Do you have Win32::API installed on your system?

      I don't think it is included by default.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://428581]
Approved by BrowserUk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found