CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Net::Ping->new("icmp") says bad file descriptor

 



bigteks
Novice

Feb 10, 2016, 8:35 AM

Post #1 of 7 (2943 views)
Net::Ping->new("icmp") says bad file descriptor Can't Post

This code is out of a batch of example code I am working through:

#!/bin/perl

use strict;
use warnings;

use Net::Ping;

my $host = "localhost";
my $p = Net::Ping->new("icmp");
print "$host is alive.\n" if $p->ping($host);

$p->close();

When I run it I get:

icmp socket error - Bad file descriptor at ./ping.pl line 9.


This is for perl 5.22.0

This really seems to me like how the docs say to use it and I can't figure out what is wrong. If I remove the argument from the new() call, it works as expected. It doesn't seem to like the "icmp" argument.




FishMonger
Veteran / Moderator

Feb 10, 2016, 9:12 AM

Post #2 of 7 (2936 views)
Re: [bigteks] Net::Ping->new("icmp") says bad file descriptor [In reply to] Can't Post

It works fine for me.

Are you sure you're not executing a different version of your script?

Do you receive the same error if you use the actual hostname instead of localhost?

Do you receive the same error if you use 127.0.0.1 or the actual IP address?

Do you receive the same error if you specify tcp instead of icmp?


(This post was edited by FishMonger on Feb 10, 2016, 9:13 AM)


bigteks
Novice

Feb 10, 2016, 11:10 AM

Post #3 of 7 (2929 views)
Re: [FishMonger] Net::Ping->new("icmp") says bad file descriptor [In reply to] Can't Post

Possibly a security block on this host, this is a locked down OS/network environment, they might have icmp blocked, does Net::Ping use something else besides icmp with no argument?


bigteks
Novice

Feb 10, 2016, 11:16 AM

Post #4 of 7 (2927 views)
Re: [FishMonger] Net::Ping->new("icmp") says bad file descriptor [In reply to] Can't Post

To answer your questions:

1. Yes I am sure
2. Same
3. Same - for both loopback & true IP
4. tcp works


FishMonger
Veteran / Moderator

Feb 10, 2016, 11:47 AM

Post #5 of 7 (2921 views)
Re: [bigteks] Net::Ping->new("icmp") says bad file descriptor [In reply to] Can't Post

Firewall rules can block icmp requests and is very common to do so, but I would not expect it to be blocked by its own request to localhost or the loopback address. Blocking rules like this are normally meant to drop requests from remote connections, not localhost, but the rule can be configured to block all requests.

Have you tried pinging another device in the same LAN? Does that give the same error?

The default protocol used is tcp, but if you see a difference in functionality between specifying and not specifying tcp, then that could indicate a bug in the module.


FishMonger
Veteran / Moderator

Feb 10, 2016, 11:50 AM

Post #6 of 7 (2920 views)
Re: [bigteks] Net::Ping->new("icmp") says bad file descriptor [In reply to] Can't Post

Are you running the script as root, or a non privileged user?

To ping via icmp, you need to run the script as root.

Quoted from the module documentation.

Quote
Specifying the "icmp" protocol requires that the program be run as root or that the program be setuid to root.



(This post was edited by FishMonger on Feb 10, 2016, 11:52 AM)


bigteks
Novice

Feb 10, 2016, 12:11 PM

Post #7 of 7 (2916 views)
Re: [FishMonger] Net::Ping->new("icmp") says bad file descriptor [In reply to] Can't Post

Thanks - that is the problem - although this is on Windows so I assume it would be run as administrator as the root equivalent


(This post was edited by bigteks on Feb 10, 2016, 12:12 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives