use strict; use IO::Socket::INET; use Socket; package mship; ############## 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";; } ############# sub mstat ############# { my ( $ip, $tcp_port ) = @_; my $status = "Up"; my $sock = IO::Socket::INET ->new( Timeout => 5, PeerAddr => $ip, PeerPort => $tcp_port, Proto => 'tcp' ) or $status = "Down"; return ($status); die "Unable to return the value of \$status\n"; } 1;