117d3 Ping from Perl? - Perl Programming
Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Ping from Perl?

Posted by enquirer (enquirer), 1 May 2004
How can I test whether a computer is visible on the network in a Perl program?

Posted by admin (Graham Ellis), 1 May 2004
The Net:ing module is probably the best way to do this - available from the CPAN if you don't already have it loaded.

Here's a module I use to test for web servers running on port 80 ... you can also test for icmp (or udp) rather than tcp visibility - icmp is the "normal" ping but has to be run with admin privelidge.

Code:
use Net::Ping;

package seehost;

# Wrapper around Ping. Wrapper can be amended as need be to tune ping params

sub testhost {
       $p = new Net::Ping("tcp");
       $p->{port_num}=80;
       @result = $p -> ping($_[0],2);
       $result[0];
       }

1;


Built into a program on our inhouse network, this allows us to check all our systems in a few seconds - it does involve a bit of forking (perhaps I should post this as a separate thread?) but we get results like:

Code:
Testing the network (port 80) ...
... ... ...
192.168.200.65 (wind) responded
... ... ...
192.168.200.134 (penguin) responded
...
192.168.200.144 (thursday) responded
192.168.200.145 (friday) responded
192.168.200.160 (mars) responded
...
192.168.200.176 (nan.wellho.co.uk) responded
...
192.168.200.188 (biriani) responded
192.168.200.189 (macdougall) responded
192.168.200.190 (pasanda) responded
192.168.200.193 (tea) responded
...
192.168.200.203 (saturn) responded
...
192.168.200.230 (panther) responded
... ...
Testing completed Trainer's console connected via wireless
Projection laptop connected via wireless
Cable and backup ISDN internet connections both present





This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2013: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho
0