#!/usr/bin/perl -w use strict; use Expect; |++; print "Content-type: text/html\n\n"; my $username="testuser"; my $password="password"; my $host="localhost"; my $timeout=7; my $exp = new Expect; # create our important expet object telnet_login($username,$password,$host,\$exp); $exp->expect($timeout, ['ncorrect', sub { print "
\n"; } } sub telnet_login { my ($username, $password, $host, $exp) = @_; my $TELNET = "/usr/bin/telnet"; my $timeout = 7; $$exp->raw_pty(1); #treat this terminal as a raw file $$exp->log_stdout(0); #do not show terminal output to STD Out $$exp->spawn("$TELNET $host") || die "Cannot open telnet\n"; # try to startup $TELNET $$exp->expect($timeout, ['ogin:', sub { $$exp->send("$username\n"); exp_continue; } ], ['assword:', sub { $$exp->send("$password\n"); } ], [timeout => sub { die "
##
bin/sh
testuser pts/5 localhost Mon Jun 16 09:16 still logged in
testuser pts/5 localhost Mon Jun 16 09:14 - 09:15 (00:00)
testuser pts/5 localhost Mon Jun 16 09:09 - 09:09 (00:00)
testuser pts/5 localhost Mon Jun 16 09:08 - 09:08 (00:00)
testuser pts/6 localhost Mon Jun 16 09:07 - 09:08 (00:00)
testuser pts/5 localhost Mon Jun 16 09:07 - 09:07 (00:00)
testuser pts/5 testuser Fri Jun 13 15:54 - 15:55 (00:00)
testuser pts/5 testuser Fri Jun 13 15:53 - 15:54 (00:00)
testuser pts/5 testuser Fri Jun 13 15:52 - 15:53 (00:00)
testuser pts/5 testuser Fri Jun 13 15:52 - 15:52 (00:00)
root:x:0:1::/:/sbin/sh
daemon:x:1:1::/:
bin:x:2:2::/usr/bin:
sys:x:3:3::/:
adm:x:4:4:Admin:/var/adm:
lp:x:71:8:Line Printer Admin:/usr/spool/lp:
uucp:x:5:5:uucp Admin:/usr/lib/uucp:
nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico
listen:x:37:4:Network Admin:/usr/net/nls:
nobody:x:60001:60001:Nobody:/:
noaccess:x:60002:60002:No Access User:/:
nobody4:x:65534:65534:SunOS 4.x Nobody:/:
fast:x:204:1:FastTrack Server:/web:/bin/sh
postfix:x:100:1:postfix:/dev/null:/bin/false
vscan:x:1001:10:Amavis User:/usr/local/encap/amavis-perl-11:/bin/sh
sshd:x:22000:22000:SSHD privsep User:/var/empty:/bin/false