thread ping

2004-06-01 Thread Eckart Uhlig
Hi all,
I have to measure the ping reply time for several ip addresses. The
problem is, I don't want to wait for the reply of the ping to ip1 and
send then the ping to ip2. Both pings should go out almost in parallel
on the line. Furthermore ip1  ip2 should be pinged more than one time
e.g. 5 times. I have solution which works with AS perl 5.8  WinXP (see
below). 

My question is now: Is this approach completly naiv or are there better
ways to do this. I mean first tests showed plausible results (checked
with external equipment), but I don't have a feeling how this script
will perform if I have to test more than one ip address and if the
results are then still correct. Has anyone experiences to share?

Thank you in advance.
Ciao
Eckart  



 begin 

use threads;
use strict;
use Net::Ping;

my ($ping1, $ping2);
my $cnt ; 

while ($cnt++  5 )
{
$ping1 = threads-new(\pn, 192.168.2.60);
$ping2 = threads-new(\pn, 192.168.2.1 );
}

$ping1-join;
$ping2-join;

sub pn 
{
my ($host)[EMAIL PROTECTED];
my $ret;
my $dur;
my $ip;

my $p = Net::Ping-new(icmp);
$p-hires();
($ret, $dur, $ip) = $p-ping($host,1);
if ($ret)
{
printf($host is alive (packet return time: %.2f ms)\n,
1000 * $dur);
}
else 
{
print host $host is not reachable.\n;
}
undef($p);
}

 end 

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: thread ping

2004-06-01 Thread Mike Jackson
I don't think using hires() in a threaded app is a great idea - ping/hires() calls are 
generally implemented by hogging the cpu, which would skew other results. Apart from 
that, looks like a perfectly legitimate threaded multi-host pinger :)
each thread should be able to accumulate and aggregate results for each host on their 
own - how you will collate these results, and detect when they're all in is another 
exercise altogether!
On Tue, 1 Jun 2004 23:54:47 +0200, Eckart Uhlig [EMAIL PROTECTED] wrote:
Hi all,
I have to measure the ping reply time for several ip addresses. The
problem is, I don't want to wait for the reply of the ping to ip1 and
send then the ping to ip2. Both pings should go out almost in parallel
on the line. Furthermore ip1  ip2 should be pinged more than one time
e.g. 5 times. I have solution which works with AS perl 5.8  WinXP (see
below).
My question is now: Is this approach completly naiv or are there better
ways to do this. I mean first tests showed plausible results (checked
with external equipment), but I don't have a feeling how this script
will perform if I have to test more than one ip address and if the
results are then still correct. Has anyone experiences to share?
Thank you in advance.
Ciao
Eckart

 begin
use threads;
use strict;
use Net::Ping;
my ($ping1, $ping2);
my $cnt ;
while ($cnt++  5 )
{
$ping1 = threads-new(\pn, 192.168.2.60);
$ping2 = threads-new(\pn, 192.168.2.1 );
}
$ping1-join;
$ping2-join;
sub pn
{
my ($host)[EMAIL PROTECTED];
my $ret;
my $dur;
my $ip;

my $p = Net::Ping-new(icmp);
$p-hires();
($ret, $dur, $ip) = $p-ping($host,1);
if ($ret)
{
printf($host is alive (packet return time: %.2f ms)\n,
1000 * $dur);
}
else
{
print host $host is not reachable.\n;
}
undef($p);
}
 end
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs