our
$VERSION
=
'0.01'
;
sub
new {
my
(
$class
,
%params
) =
@_
;
my
%self
= (
'debug'
=> 0,
'password'
=>
''
,
'port'
=> 23,
'server'
=>
undef
,
'telnet'
=>
'telnet'
,
'timeout'
=> 10,
'username'
=>
'guest'
);
while
(
my
(
$k
,
$v
) =
each
(
%params
)) {
$self
{
$k
} =
$v
if
(
exists
$self
{
$k
});
}
return
bless
(\
%self
,
$class
);
}
sub
connect
{
my
$self
=
shift
();
$self
->{
'expect'
} = Expect->spawn(
$self
->{
'telnet'
},
$self
->{
'server'
},
$self
->{
'port'
});
$self
->{
'expect'
}->log_stdout(0);
return
undef
unless
(
defined
(
$self
->_login(
$self
)));
return
$self
->{
'expect'
};
}
sub
_login {
my
$self
=
shift
();
my
$bot
=
$self
->{
'expect'
};
my
$debug
=
$self
->{
'debug'
};
print
(
"Waiting for login\n"
)
if
(
$debug
);
$bot
->expect(
$self
->{
'timeout'
},
'-re'
,
'½Ð¿é¤J¥N¸¹'
);
return
undef
if
(
$bot
->error());
$bot
->
send
(
$self
->{
'username'
},
"\n[D[D[D[D"
);
return
1;
}
sub
query {
my
(
$self
,
$user
) =
@_
;
my
$bot
=
$self
->{
'expect'
};
my
$debug
=
$self
->{
'debug'
};
my
$timeout
=
$self
->{
'timeout'
};
$bot
->
send
(
"[D[Dt\nq\n"
,
$user
,
"\n"
);
my
%h
;
print
(
"Waiting for nickname, logintimes, and posttimes\n"
)
if
(
$debug
);
$bot
->expect(
$timeout
,
'-re'
,
'\w+\((.*)\)\s?¤W¯¸\s?(\d+)\s?¦¸¡A¤å³¹\s?(\d+)\s?½g¡A'
);
$h
{
'nickname'
} = (
$bot
->matchlist)[0];
$h
{
'logintimes'
} = (
$bot
->matchlist)[1];
$h
{
'posttimes'
} = (
$bot
->matchlist)[2];
printf
(
"nickname = %s\n"
,
$h
{
'nickname'
})
if
(
$debug
);
printf
(
"logintimes = %s\n"
,
$h
{
'logintimes'
})
if
(
$debug
);
printf
(
"posttimes = %s\n"
,
$h
{
'posttimes'
})
if
(
$debug
);
return
undef
if
(
$bot
->error());
print
(
"Waiting for lastelogintime and lastloginip\n"
)
if
(
$debug
);
$bot
->expect(
$timeout
,
'-re'
,
'¤W¦¸\((.+)\)¨Ó¦Û\((\S+)\)'
);
$h
{
'lastlogintime'
} = (
$bot
->matchlist)[0];
$h
{
'lastloginip'
} = (
$bot
->matchlist)[1];
printf
(
"lastlogintime = %s\n"
,
$h
{
'lastlogintime'
})
if
(
$debug
);
printf
(
"lastloginip = %s\n"
,
$h
{
'lastloginip'
})
if
(
$debug
);
return
undef
if
(
$bot
->error());
return
\
%h
;
}
1;