- 论坛徽章:
- 0
|
这个问题想了好久。。好像shell下面没有直接调用的东西,来让我做用户名和密码的验证。于是想到了自己写一个。
原理:用ssh,连接本地,然后判断用户名密码是否正确。
代码:(需要expect支持,另:expect 需要tcl支持)
#!/root/download/expect-5.30/expect -f
#usage:shell_test name password
if {$argc!=2}\
{
send_user "Usage:shell_test name password"
exit 1
}
set name [lindex $argv 0]
set password [lindex $argv 1]
set isSend 0
spawn ssh -t "${name}@localhost"
expect \
{
"* (yes/no)*" {send "yes\r"} \
"* password:*" \
{
send "${password}\r"
set isSend 1
} \
default {send_user "error"}
}
if {$isSend==0}\
{
expect "* password:*" {send "${password}\r"} \
default {send_user "error"}
}
expect \
{
"Permission denied" {send_user "Not allowed"} \
"*~]" \
{
send_user "OK"
send "exit\r"
} \
default \
{
send_user "error"
exit 1
}
}
exit 0
有没有高人给点建议,应该怎么认证啊.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/14673/showart_289691.html |
|