in reply to Net::Ping blowed my mind
You did not chomp your input, so $url contains a new line if you don't run the script with the url on the command line. If you do run it on the command line, the diamond operator actually is looking for file names. By default Net::Ping attempts to establish a connection to the remote host's echo port via TCP, which may not be what you expect, since normal OS ping is an ICMP ping. If you want this behavior, 'icmp' has to be passed to the Net::Ping constructor.
So this works:#!/usr/bin/env perl use Net::Ping; $url = <>; chomp $url; $p = Net::Ping->new('icmp'); if ($p->ping($url)) { print "working"; } else {print "not working"; }
And finally the script is ran like this: sudo ./t1.pl text~$ cat text yahoo.com
|
---|