Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Usage of IO::Socket::PortState

by born4blog (Initiate)
on Jun 06, 2013 at 00:30 UTC ( [id://1037332]=perlquestion: print w/replies, xml ) Need Help??

born4blog has asked for the wisdom of the Perl Monks concerning the following question:

I know this is a stupid question. I'm a starter in Perl even for scripting. Could anybody tell me how to use the cpan module IO::Socket::PortState ? I just want to check whether given port is enabled on the remote server. I've gone through the how to on cpan page, but I can't understand it. If anyone explain the usage it would be very helpful for beginners like me Thanks

Replies are listed 'Best First'.
Re: Usage of IO::Socket::PortState
by Khen1950fx (Canon) on Jun 06, 2013 at 04:04 UTC
    See: Testing for port connectivity. JSchmitz shows you how to get the status of a single port, and McDarren shows how to handle multiple hosts. Here's an example:
    #!/usr/bin/perl use strict; use warnings; use IO::Socket::PortState qw(check_ports); my $proto = 'tcp'; my $port = '80'; my $address = '127.0.0.1'; my($section, $ping_timeout, %porthash); $porthash{$proto}{$port}{'name'} = $section; check_ports($address, $ping_timeout, \%porthash); my $open = $porthash{$proto}{$port}{'open'}; if ($open) { print "alive\n"; } else { print "dead\n"; }
Re: Usage of IO::Socket::PortState (docs)
by Anonymous Monk on Jun 06, 2013 at 00:33 UTC

    Surely the docs can tell you how to use it? Lets check  [mod://IO::Socket::PortState] IO::Socket::PortState .. I checked, they do tell you how to use it

      The problem is I couldn't understand it :( Could you please paste a snippet on how to check the status of port?

      Thanks

        The problem is I couldn't understand it :( Could you please paste a snippet on how to check the status of port?

        Couldn't understand what?

        You mean you couldn't understand %porthash ? There is an example if you scroll down , or search for "porthash"

        This is how docs work, short stuff on top, details below :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1037332]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-24 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found