#!/usr/bin/perl use strict; $| = 1; use Socket; use Fcntl; use Errno; sub packaddr { my ($host, $port) = split(/:/, $_[0]); my (undef, undef, undef, undef, $hostaddr) = gethostbyname($host); return pack('S n a4 x8', &AF_INET, $port, $hostaddr); } if(socket(SOCK, &PF_INET, &SOCK_STREAM, 0)) { if(connect(SOCK, packaddr($ARGV[0]))) { print "$ARGV[0]: connected\n"; system('stty', '-icanon', 'eol', "\001"); while(defined(my $c = getc(STDIN))) { print "\n"; my $id; if(($c >= 1) && ($c <= 9)) { $id = $c - 1; } elsif($c == 0) { $id = 10; } elsif(ord($c) >= ord('a')) { $id = ord($c) - ord('a') }; my $response; send(SOCK, "select $id\n", 0); recv(SOCK, $response, 256, 0); print $response; } } else { print "connect failed: $!\n"; } close(SOCK); } else { print "socket failed: $!\n"; }