Sponsored Content
Top Forums Shell Programming and Scripting Perl : code on ping showing difference result Post 302766693 by scriptscript on Tuesday 5th of February 2013 06:57:28 AM
Old 02-05-2013
Perl : code on ping showing difference result

Hi all,

I am using the below code to ping a code and print whehter the connection is successful or not.
Code:
    use Net::Ping;
    $p = Net::Ping->new();    
    my $host = "x.x.x.x";
   # print "$host is alive.\n" if $p->ping($host);
    if ($p->ping($host,3))
    {
        print "success";
    }
    else
    {
         print "Fail";
    }     
    $p->close();

For one IP address.. I received the status as "Fail" . But when tried using start->run-> cmd ->ping ipaddress .. the ping is successful.

COuld you let me know any other alternative code to ping the device.

---------- Post updated at 06:57 AM ---------- Previous update was at 06:50 AM ----------

Hi all,

I am using the below code to ping a code and print whehter the connection is successful or not.
Code:
    use Net::Ping;
    $p = Net::Ping->new();    
    my $host = "x.x.x.x";
   # print "$host is alive.\n" if $p->ping($host);
    if ($p->ping($host,3))
    {
        print "success";
    }
    else
    {
         print "Fail";
    }     
    $p->close();

For one IP address.. I received the status as "Fail" . But when tried using start->run-> cmd ->ping ipaddress .. the ping is successful.

COuld you let me know any other alternative code to ping the device.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PERL: ping and e-mail

I need a script to open a text file with ip's in it, ping them, split the results into the ip and time from the results and e-mail them ? here what i've done. its porbly wrong and not workin.its for win nt4 use Net::SMTP; # get list of ip's to ping open (PINGFILE, "< c:\\Documents and... (20 Replies)
Discussion started by: perleo
20 Replies

2. Shell Programming and Scripting

defined value not showing....in the result

Hi, PLMN=APPLE awk ' /is missing/ { flag=1;print > "fruit_output_m1.txt" } END { if( flag != 1 ) print "No $PLMN in the store." > "fruit_output_n1.txt" } ' fruit_result.txt The output is: No $PLMN in the store. Should be: No APPLE in the store. Please help!! (1 Reply)
Discussion started by: happyv
1 Replies

3. Shell Programming and Scripting

Help with showing the difference in two lines of input

I would like my script to be able to tell the difference between to lines of input, like: Input 1: 1 2 3 4 5 Input 2: 1 2 3 4 5 6 I want the script to tell me that the difference between the two lines is the 6. Is there anyway I can have it do this? Here's an example of what my script... (12 Replies)
Discussion started by: Kweekwom
12 Replies

4. Shell Programming and Scripting

perl ping script

Dear All Any one able been writing any command ping in perl??basically i want to wring ping script to send 1000 packet ping then initiate "Ctrl C' terminal to ping example below:-] #!/usr/local/bin/perl $r=`/bin/ping 172.23.11.254`; Thank You ---------- Post updated at 10:27 PM ----------... (2 Replies)
Discussion started by: netxus
2 Replies

5. Programming

Perl Ping Loop

Hi All i have an issue with ping, we are using dhcp and so if the machine has been offline and i ping it, i get " ping: unknown host <hostname> is there a way i can stick a loop somewhere so it would keep trying when it got the unknown host error and then when the machine came back online... (2 Replies)
Discussion started by: ab52
2 Replies

6. Shell Programming and Scripting

Ping and Perl

Hi There i have little situation that i could us some help with. We have a dhcp server, but the problem is if that a machine has been offline for a while it loose it's lease and so if you ping it you get unknown host if there a way using perl that it will continue to try and ping it, even tho... (1 Reply)
Discussion started by: ab52
1 Replies

7. Solaris

solaris link aggregation problem , once i reboot it is not showing, not able to ping the default gat

Hi All, I am trying to aggregate the NIC's,(igb2 and igb3) (igb0 is used by the physical system and igb1 is used by primary-vsw0) to create the domains on that for faster data transfer, I followed the process for creating the aggregation, dladm create-aggr -d igb2 -d igb3 1 after creating the... (2 Replies)
Discussion started by: buildscm
2 Replies

8. Shell Programming and Scripting

Ping result talking too long

Hello all, I am writing a script that pings various machines to check connectivity. If a machine is available, the prompt returns a result immediately: root@ops # ping 172.21.5.5 172.21.5.5 is alive BUT if a machine is Down , the reply takes a long time to come. The issue is I want to... (1 Reply)
Discussion started by: Junaid Subhani
1 Replies

9. Shell Programming and Scripting

Ssh on ping result?

I still haven't had chance to read the entire Debian manual, which I promise I will do as soon as I can, and I will start putting info back into this forum. However, for the mean time, could someone please help with a small script? I understand what I've got to do and how to do it, but I'm... (13 Replies)
Discussion started by: MuntyScrunt
13 Replies
AnyEvent::XMPP::Ext::Ping(3pm)				User Contributed Perl Documentation			    AnyEvent::XMPP::Ext::Ping(3pm)

NAME
AnyEvent::XMPP::Ext::Ping - Implementation of XMPP Ping XEP-0199 SYNOPSIS
use AnyEvent::XMPP::Ext::Ping; my $con = AnyEvent::XMPP::IM::Connection->new (...); $con->add_extension (my $ping = AnyEvent::XMPP::Ext::Ping->new); # this enables auto-timeout of a connection if it didn't answer # within 120 seconds to a ping with a reply $ping->enable_timeout ($con, 120); my $cl = AnyEvent::XMPP::Client->new (...); $cl->add_extension (my $ping = AnyEvent::XMPP::Ext::Ping->new); # this enables auto-timeout of newly created connections $ping->auto_timeout(120); $ping->ping ($con, 'ping_dest@server.tld', sub { my ($time, $error) = @_; if ($error) { # we got an error } # $time is a float (seconds) of the rtt if you got Time::HiRes }); DESCRIPTION
This extension implements XEP-0199: XMPP Ping. It allows you to define a automatic ping timeouter that will disconnect dead connections (which didn't reply to a ping after N seconds). See also the documentation of the "enable_timeout" method below. It also allows you to send pings to any XMPP entity you like and will measure the time it took if you got Time::HiRes. METHODS
new (%args) Creates a new ping handle. auto_timeout ($timeout) This method enables automatic connection timeout of new connections. It calls "enable_timeout" (see below) for every new connection that was connected and emitted a "stream_ready" event. This is useful if you want connections that have this extension automatically timeouted. In particular this is useful with modules like AnyEvent::XMPP::Client (see also SYNOPSIS above). enable_timeout ($con, $timeout) This enables a periodical ping on the connection $con. $timeout must be the seconds that the ping intervals last. If the server which is connected via $con didn't respond within $timeout seconds the connection $con will be disconnected. Please note that there already is a basic timeout mechanism for dead TCP connections in AnyEvent::XMPP::Connection, see also the "whitespace_ping_interval" configuration variable for a connection there. It then will depend on TCP timeouts to disconnect the connection. Use "enable_timeout" and "auto_timeout" only if you really feel like you need an explicit timeout for your connections. ping ($con, $dest, $cb, $timeout) This method sends a ping request to $dest via the AnyEvent::XMPP::Connection in $con. If $dest is undefined the ping will be sent to the connected server. $cb will be called when either the ping timeouts, an error occurs or the ping result was received. $timeout is an optional timeout for the ping request, if $timeout is not given the default IQ timeout for the connection is the relevant timeout. The first argument to $cb will be the seconds of the round trip time for that request (If you have Time::HiRes). If you don't have Time::HiRes installed the first argument will be undef. The second argument to $cb will be either undef if no error occured or a AnyEvent::XMPP::Error::IQ error object. ignore_pings ($bool) This method is mostly for testing, it tells this extension to ignore all ping requests and will prevent any response from being sent. AUTHOR
Robin Redeker, "<elmex at ta-sa.org>", JID: "<elmex at jabber.org>" COPYRIGHT &; LICENSE Copyright 2007, 2008 Robin Redeker, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-01-23 AnyEvent::XMPP::Ext::Ping(3pm)
All times are GMT -4. The time now is 09:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy