title: How to check the presence of the internet connection in Perl?
body: <p>I have a simple script that verifies periodically (once every few seconds) if there is internet connectivity from that server. To be clear, it's not about to check if an external site/service/server is alive. As reliable internet destinations I use IPs of sites like google, yahoo, etc. Normally I use 3 destinations  (LAN, ISP network, outside ISP)</p>
  
  <p>My current code responsible for this is just a simple and dirty call to <code>ping</code>:</p>
  
  <pre><code>    my $pingResponse = `ping -c 1 -w 1 123.123.123.123`;
      my $isConnected = parsePingResponse($pingResponse);
  </code></pre>
  
  <p>It seems to work, but I'm sure it's not the right/best way to accomplish this task. There are at least 3 drawbacks: external system call, it's slow, it has a relatively long <em>deadline</em> of 1 second.  </p>
  
  <p>So, my question is: how to implement simply and efficiently a <em>ping</em> functionality the <em>perlish</em> way in order to verify if the internet connection is alive?  </p>
  
  <p>(I think LWP is an overkill. It's not important if a site or a page is available, just if some external IPs are reachable. Probably it should be something simple involving low-level networking)</p>