Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2004188
  • 博文数量: 369
  • 博客积分: 10093
  • 博客等级: 上将
  • 技术积分: 4271
  • 用 户 组: 普通用户
  • 注册时间: 2005-03-21 00:59
文章分类

全部博文(369)

文章存档

2013年(1)

2011年(2)

2010年(10)

2009年(16)

2008年(33)

2007年(146)

2006年(160)

2005年(1)

分类:

2006-02-23 03:48:47

功能实现:
 1)自动登陆,通过在MENU间切换来防止发呆和掉线。
 2)聊天的自动应答。
适用方法:
 1)修改程序中的用户名xiaosuo为你自己的用户名。
 2)启动程序,输入密码。
谨以此程序献给icymoon姐姐!
#!/usr/bin/expect -f

set username xiaosuo
set hostname nkbbs.org

set timeout -1
spawn telnet -8 $hostname

# send the user name
expect {
        "防止使用程式上站"      {
                send "\003"             # send Ctrl + C
                exp_continue
        }
        "请输入帐号"            {
                send "$username\r"
        }
}

# send the password
expect {
        "无此 ID" {
                puts "没有这个用户名,请检察"
                exit
        }
        "只能从主机登陆" {
                puts "SYSOP 只能从主机登陆"
                exit
        }
        "不可从此IP登录本站" {
                puts "不可从此IP登录本站"
                exit
        }
        "没有得到email验证" {
                puts "注册信息没有得到email验证。请回复后用WEB登陆自动激活"
                exit
        }
        "请输入密码" {
        }
}

# get the password from the user
stty -echo
expect_user -notransfer -re "(.*)\n"
# so BT, no space between '1' and 'string', waste me much time
set password $expect_out(1,string)
stty echo
send "$password\r"

# check the password
expect {
        "密码输入错误" {
                puts "密码错误"
                exit
        }
        -re "按.*键继续" {
                send "\r"
        }
        "您想删除重复的 login 吗" {
                send "\r\r"
        }
}
# jump the issue
for {set i 0} {$i<2} {incr i} {
        send "\r"
}

expect {
        "您要删除以上密码输入错误的记录吗" {
                send "Y\r"
                exp_continue
        }
        -re "好朋友列表" {
                send "q"
                exp_continue
        }
        -re {\(.*[0-9][0-9]:[0-9][0-9].*\):} {
                send "\r"
                exp_continue
        }
        -re "主选单" {
                send "e\r"
        }
}

# Somebody want to chat with you.
expect_after {
        -re {\(.*[0-9][0-9]:[0-9][0-9].*\):} {
                send "r我是挂BBS机器人!:)\r"
        }
}

set timeout 10
# Keep alive loop.
while {1} {
        expect {
                timeout {
                        send "e\r"
                }
        }
}


阅读(1313) | 评论(1) | 转发(0) |
0

上一篇:感冒了

下一篇:XUL -- XML User interface Language

给主人留下些什么吧!~~