use strict; use warnings; package mship; use IO::Socket::INET; use Socket; =head1 NAME mship - The mothership connection or how I learned to stop worrying and trust the script. =head1 VERSION Version 0.03 =cut our $VERSION = '0.03'; =head1 SYNOPSIS use mship; my %status=mship::connection('IP', 'TCP_PORT'); my $status=mship::mstat('IP', 'TCP_PORT') ? "Up" : "Down"; ... =head1 FUNCTIONS =head2 connection =cut ############## sub connection ############## { my $IP = shift; my $TCP_PORT = shift; my ( $ipadd, $port_name, $remote_name ); $ipadd = Socket::inet_aton($IP) or die "$IP is not valid\n"; $port_name = getservbyport($TCP_PORT, 'tcp') or $port_name = "unknown"; $remote_name = gethostbyaddr( $ipadd, 2 ) or die "Unable to resolve hostname for $IP\n"; my %stats = ( 'IP' => $IP, 'PORT' => $TCP_PORT, 'port_name' => $port_name, 'remote_name' => $remote_name, 'status' => &mstat($IP, $TCP_PORT) ); print "sub connection port = $TCP_PORT IP = $IP\n"; return %stats or die "unable to return the value of \%stats\n";; } =head2 mstat =cut ############# sub mstat ############# { my ( $ip, $tcp_port ) = @_; my $sock = IO::Socket::INET ->new( Timeout => 5, PeerAddr => $ip, PeerPort => $tcp_port, Proto => 'tcp' ); return $sock ? 1 : 0; } =head1 AUTHOR Ted Fiedler, C<< <fiedlert@gmail.com> >> =head1 BUGS Please report any bugs or feature requests to C<fiedlert@gmail.com> =head1 ACKNOWLEDGEMENTS =head1 COPYRIGHT & LICENSE Copyright 2003, 2004, 2005 Ted Fiedler, All Rights Reserved. This program is free software; you can redistribute it and/or modify i +t under the same terms as Perl itself. =cut 1; # End of mship
In reply to mship.pm - my first module by tcf03
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |