Assuming TCP connection to some server (sshd on port 22 in the example below), here's an example:
...
my $remoteIP ='a.b.c.d';
my $port = 22; #aiming for sshd - use your own port here
my $iaddr = inet_aton($remoteIP) || die("No $remoteIP around");
my $paddr = sockaddr_in($port, $iaddr);
my $protocol = getprotobyname('tcp');
socket(SOCK, PF_INET, SOCK_STREAM, $protocol) || die("socket() fai
+led: $!");
connect(SOCK, $paddr) || die("connect() failed: $!");
$line = <SOCK>; #read a line
print("$line online\n"); #print it
close(SOCK); #close socket
...
|