1 #!/usr/bin/perl -w
 2 # File: telnet_socket.pl
 3 # Author: Tom Large - tlarge@thelug.org
 4 # Location: http://www.thelug.org/docs/
 5 # Description: Demonstrates how to make a TCP socket connection
 6 # using the IO::Socket module.
 7 
 8 use IO::Socket;
 9 
10 $remote_host = "x.x.x.x";
11 $remote_port = "nnnn";
12 
13 print "Connecting to $remote_host now...\n";
14 $socket = IO::Socket::INET->new(PeerAddr => $remote_host,
15                                 PeerPort => $remote_port,
16                                 Proto    => "tcp",
17                                 Type     => SOCK_STREAM)
18     or die "Couldn't connect to $remote_host:$remote_port : $@\n";
19 
20 print $socket "This is a test.";
21 print $socket "quit";
22 
23 print "Closing socket connection.\n";
24 close($socket);


syntax highlighted by Code2HTML, v. 0.9.1