#!/usr/bin/perl -w use IO::Socket; use Net::hostent; # for OO version of gethostbyaddr $PORT = 9000; # pick something not in use $prompt="MA5680T>"; $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; print "[Server $0 accepting clients]\n"; while ($client = $server->accept()) { $client->autoflush(1); #print $client "Welcome to $0; type help for command list.\n"; #$hostinfo = gethostbyaddr($client->peeraddr); #printf "[Connect from %s]\n", $hostinfo->name || $client->peerhost; print $client "\n"; print $client "Warning: Telnet is not a secure protocol, and it is recommended to use Stelnet."; print $client "\n"; print $client "\n"; print $client ">>User name:"; while ( <$client>) { next unless /\S/; # blank line print "\nlinea :$_"; if (/quit|exit/i) { last; } elsif (/leo/i) { printf $client "\n>>User password:"; } elsif (/password/i) { printf $client "\n$prompt"; } else { print $client "\n$prompt"; } } continue { #print $client $prompt; } close $client; }