Hi there, I am working on a script that need to ping a host. In the past I have accomplished this with Net::Ping. For some reason this time Net::Ping will NOT work for me.

At first I thought maybe it was my script, so I made a really small perl script to check that it was NOT my script.

#!/usr/bin/perl use strict; use warnings; use Net::Ping; my $target = 'esxi01'; my $ping_obj = Net::Ping->new(); if ($ping_obj->ping($target)) { print "Yes, I can ping $target\n"; } else { print "No, I cannot ping $target\n"; }

The script fails to ping anything but 127.0.0.1

**Update**

After plugging the right word in the magical Google, I got post from someone who had the same problem and their problem was fixed by doing;

 my $ping_obj = Net::Ping->new('icmp');

The part I cannot figure out is why does it work when specify "icmp" but not work when I use the defaults? That is how I have used it in the past and it worked fine.

I just tried to test for an open port using the function I have used in my last script(s), once again I made a test script based off the once above with the needed modifications.

#!/usr/bin/perl use strict; use warnings; use Net::Ping; my $target = 'esxi01'; my $ping_obj = Net::Ping->new('tcp'); $ping_obj->service_check('1'); $ping_obj->port_number('22'); if ($ping_obj->ping($target)) { print "Yes, I can ping $target\n"; } else { print "No, I cannot ping $target\n"; } $ping_obj->close();

This script also tells me the host is not pingable but yet I can already get into via SSH so its very much alive and open.

What is going on here?

In reply to Solution to broken Net::Ping by solignis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.