Chinaunix首页 | 论坛 | 博客
  • 博客访问: 13168
  • 博文数量: 7
  • 博客积分: 250
  • 博客等级: 二等列兵
  • 技术积分: 75
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-20 12:57
文章分类

全部博文(7)

文章存档

2011年(1)

2010年(1)

2009年(5)

我的朋友
最近访客

分类:

2009-09-30 00:03:57

LINUX的机器一般用的是SECURITY CRT去管理,管理的机器多了,每台输密码也很辛苦,SECURITY CRT有一个自动匹配的功能,本来可以在每个SESSION里配置,但是机器的密码还是需要经常改的,一改,N多机器要重新配置一遍,也够麻烦,好在CRT内置了一些对象,支持VBS等脚本语言,让用户进行管理.写了一段代码用来自动登陆,现在再也不怕改N多机器了,只需要每次改一下calpwd的function就行了.
# $language="VBSCRIPT.ENCODE"
# $interface="1.0"
'**Start Encode**
Sub Main
spPwd="test"
crt.Screen.Synchronous=True
localAddr=crt.Session.LocalAddress
localAddrArr=split(localAddr,".")
做一个简单的IP限制.使脚本不能随便使用.
if Instr(ip,"192.168.20")<>False or localAddrArr(2)<>20 or int(localAddrArr(3))>64 then
 MsgBox "You have no power to run this script!"
 Exit Sub
End if
pathArr=split(crt.Session.Path,"\")
set regObj=new RegExp
regObj.Global=Truesupp
regObj.Pattern="[^0-9.]"
ip=pathArr(UBound(pathArr))
ip=regObj.Replace(ip,"")
ipArray=split(ip,".")
ipNum=UBound(ipArray)
if ipNum=0 or ipNum=2 or ipNum=-1 then
 ip=crt.Dialog.Prompt("Please enter a ip:","Which ip do you want to login?","192.168.")
 user=crt.Dialog.Prompt("username:","User to login:","test")
End if
if ipNum=1 then
 Select case ipArray(ipNum-1)
  case "159"
   ip="202.92."&ip
  case "11"
   ip="119.47."&ip
  case "12"
   ip="119.17."&ip
  case "13"
   ip="61.45."&ip
  case "18"
   ip="20.21."&ip
  case else
   ip="192.168."&ip
 End select
End if
if user="" then
 user="test"
End if
if user<>"test" then
 spPwd=crt.Dialog.Prompt("Password:","Password to login:","",True)
End if
rootPwd=calpwd(ip)
if rootPwd="" then
 exit Sub
End if  
if crt.Screen.WaitForString("]$")=True then
 crt.Screen.send "unset HISTFILE&&ssh
End if
j1=0
j2=0
j3=0
j4=0
Do Until false
retVal=crt.Screen.WaitForStrings("password:","]$","Password:","口令:","(yes/no)?","avoid man-in-the-middle attacks","Connection timed out","No route to host","Connection closed by remote host",10)
select case retVal
case 1
if j1 <> 0 then
 crt.Screen.sendkeys "^c"&VBCR
 MsgBox "test password is incorrect!"
 Exit Do
else
 crt.Screen.send spPwd&VBCR
 j1=j1+1
End if
case 2
 if j2>1 then
  Exit do
 else
  crt.Screen.send "su -"&VBCR
  j2=j2+1
 End if
case 3
 crt.Screen.Send rootPwd&VBCR
 Exit Do
case 4
 crt.Screen.Send rootPwd&VBCR
 Exit Do
case 5
 crt.Screen.Send "yes"&VBCR
case 6
 crt.Screen.sendkeys "^c"&VBCR
 Exit Do
case else
 Exit Do
End select
Loop
End Sub
function calpwd(ip)
这部分涉及机密,如何实现就看您的了.
End function
阅读(1536) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-02-02 15:47:09

英文的看得懂,其他不是很懂,呵呵