关闭

vbscript应用于netscreen防火墙检查

1061人阅读 评论(0) 收藏 举报
 程序明说:通过中转solaris系统登录多台netscreen防火墙,检查设备状态crt脚本(vbs脚本vbscript)


# $language = "VBScript"
# $interface = "1.0"

Sub Main

Cnstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=firewall.mdb;Persist Security Info=False"

tabname="setmessage"  
'dulttab="dultmess"    '填写报表数据表
'dultnametab="dult"     '值班人员表


Set cn=CreateObject("ADODB.Connection")
Set rs=CreateObject("ADODB.Recordset")
'Set rs1=CreateObject("ADODB.Recordset")
'Set rs2=CreateObject("ADODB.Recordset")

Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("testfile.txt", True)
 
 




 cn.Open Cnstr
 rs.Open "select * from "+tabname,cn,1,3


Dim cpustr,memorystr,connstr


Dim  objXL
Set objXL=CreateObject("Excel.Application")
objXL.Visible=false
'objXL.WorkBooks.Add
Set objWb = objXL.WorkBooks.Open ("c:/firewall/template.xls")

' Get the first loaded worksheet object of the current workbook
Set objWb = objXL.ActiveWorkBook.WorkSheets(1)
objWb.Activate               ' not absolutely necessary (for CSV)


'objXL.Columns(1).ColumnWidth=40
'objXL.Columns(2).ColumnWidth=40
'objXL.Columns(3).ColumnWidth=20

'objXL.Cells(1,1).Value="cpu"
'objXL.Cells(1,2).Value="memory"
'objXL.Cells(1,3).Value="connest"

 crt.Screen.Synchronous = True
 crt.Session.Connect ("/telnet 132.*")
 
  crt.Screen.WaitForString "login:"
 crt.screen.Send  "用户名" & Chr(10)
 crt.Screen.WaitForString "Password:"
 crt.screen.Send  "密码" & Chr(10)
'bug处理
 crt.Screen.WaitForString "eric@dszmas1o> "
 crt.screen.Send "df -k"  & Chr(10)
 screenrow = crt.screen.Rows 
 cpustr = crt.Screen.Get(screenrow, 1, screenrow, 110 )
 memorystr = crt.Screen.Get(screenrow, 1, screenrow, 110 )
 connstr = crt.Screen.Get(screenrow, 1, screenrow, 110 )
 crt.screen.Send  Chr(10) 
 crt.Screen.WaitForString "> "
 crt.screen.Send "echo "& cpustr  & Chr(10)
 crt.Screen.WaitForString ">"
 crt.screen.Send "echo "& memorystr & Chr(10)
 crt.Screen.WaitForString ">" 
 crt.screen.Send "echo "& connstr  & Chr(10) 
crt.screen.Send  Chr(10) 



intindex=3

Dim ipaddr,username,seten,setname,systemtype,dultname
dultname=crt.Dialog.Prompt("input dultname", "dultname", "", False)

While Not rs.eof
  ipaddr=rs("ipaddr")
  username=rs("username")
  seten=rs("seten")
  systemtype=rs("systemtype")
  setname=rs("setname")
 MyFile.WriteLine(ipaddr)
 MyFile.WriteLine(Date)
 crt.Screen.WaitForString "> "
 crt.screen.Send  "telnet "&ipaddr & Chr(10)
 crt.Screen.WaitForString "login:"
 crt.screen.Send  username & Chr(10)
 crt.Screen.WaitForString "password:"
 crt.screen.Send seten & Chr(10)

 crt.Screen.WaitForString "->"
 crt.screen.Send "get performance cpu"& Chr(10)

 crt.Screen.WaitForString "->"
 screenrow = crt.screen.Rows - 2
 cpustr = crt.Screen.Get(screenrow, 1, screenrow, 110 )
' objXL.Cells(intindex,1).value=cpustr
 crt.screen.Send "get memory"& Chr(10)


 crt.Screen.WaitForString "->"
 screenrow = crt.screen.Rows - 1
 memorystr = crt.Screen.Get(screenrow, 1, screenrow, 110 )
 'objXL.Cells(intindex,2).value=memorystr
 crt.screen.Send "get session | include alloc"& Chr(10)


 crt.Screen.WaitForString "->"
 screenrow = crt.screen.Rows - 1
 connstr = crt.Screen.Get(screenrow, 1, screenrow, 110 )
 'objXL.Cells(intindex,3).value=connstr


 crt.screen.Send "exit"& Chr(10)

'处理提处字符串的信息,通过unix系统进行数据计算(字符提取)
 objwb.Cells(intindex,6).value=datetime   '记录日期
 objwb.Cells(intindex,4).value=dultname
 objwb.Cells(intindex,13).value=setname
 objwb.Cells(intindex,14).value=systemtype
 
 objwb.Cells(intindex,18).value="正常"
 objwb.Cells(intindex,19).value="正常"
 objwb.Cells(intindex,20).value="正常"

 crt.Screen.WaitForString ">"
 crt.screen.Send "echo "& cpustr & "| awk -F" & Chr(34)&":"&Chr(34)&" '{print $2}'" & Chr(10)
 crt.Screen.WaitForString ">"
 screenrow = crt.screen.Rows - 1
 cpustr = crt.Screen.Get(screenrow, 1, screenrow, 110 )
  MyFile.WriteLine(cpustr)
 objwb.Cells(intindex,15).value=cpustr
 crt.screen.Send "echo "& memorystr & "| awk -F"&Chr(34)&" "&Chr(34)&" '{print $3,$5}'"&"| awk -F"&chr(34)&","&chr(34)&" '{printf("&chr(34)&"%3.1f%/n"& chr(34)&",$1*100/($1+$2))}'"&chr(10)
 crt.Screen.WaitForString ">" 
 screenrow = crt.screen.Rows - 1
 memorystr = crt.Screen.Get(screenrow, 1, screenrow, 110 )
 objwb.Cells(intindex,16).value=memorystr
   MyFile.WriteLine(memorystr)
 crt.screen.Send "echo "& connstr  &"|awk -F"&Chr(34)&" "&Chr(34)&" '{print $2}' | awk -F"&chr(34)&"/"&chr(34)&" '{print $1}'"&Chr(10) 
 crt.Screen.WaitForString ">"
 screenrow = crt.screen.Rows - 1
 connstr = crt.Screen.Get(screenrow, 1, screenrow, 110 )
 objwb.Cells(intindex,17).value=connstr
   MyFile.WriteLine(connstr)
 crt.screen.Send Chr(10)
intindex=intindex+1

rs.movenext





Wend
 crt.Screen.WaitForString "eric@dszmas1o> "
 crt.screen.Send  "exit" & Chr(10)
 crt.Screen.Synchronous = False


objwb.Cells.Select
objXL.Selection.Rows.AutoFit
objXL.Selection.Columns.AutoFit
objXL.cells(1,1).Select

objXL.ActiveWorkBook.SaveCopyAs("c:/firewall/ttt.xls")
objXL.Quit()                 ' Quit Excel



rs.close
 MyFile.Close
Set rs=Nothing

Set cn=Nothing

End Sub
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3650962次
    • 积分:59829
    • 等级:
    • 排名:第40名
    • 原创:1549篇
    • 转载:1252篇
    • 译文:0篇
    • 评论:459条
    最新评论