Perl : code on ping showing difference result


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl : code on ping showing difference result
# 1  
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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

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

7. 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

8. 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

9. 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
Login or Register to Ask a Question