Socket connection with Perl: checksocket.pl
Thursday, October 7, 2010 4:26:13 PM
use IO::Socket;
$remote_host="www.ap.ntdtv.com";
$remote_port="8080";
$socket = IO::Socket::INET->new(
Proto => "tcp",
Timeout => 5, # in seconds
PeerAddr => $remote_host,
PeerPort => $remote_port,
Type => SOCK_STREAM,
);
if($socket) {$success=1};
if(!$socket) {$success=0};
if($success eq 1){print "CONNECTED"};
if($success eq 0){print "NOTCONNECTED"};
close($socket);
$remote_host="www.ap.ntdtv.com";
$remote_port="8080";
$socket = IO::Socket::INET->new(
Proto => "tcp",
Timeout => 5, # in seconds
PeerAddr => $remote_host,
PeerPort => $remote_port,
Type => SOCK_STREAM,
);
if($socket) {$success=1};
if(!$socket) {$success=0};
if($success eq 1){print "CONNECTED"};
if($success eq 0){print "NOTCONNECTED"};
close($socket);






