Scripts Review

PlAwAnSaI

Administrator
ตัวอย่างการใช้งาน Syslog Server เพื่อรับ log จาก Cisco Router
Syslog Server หรืออาจจะเรียกเป็น Syslog Daemon ในที่นี้เป็นซอร์ฟแวร์ที่ทำหน้าที่ รับ, บันทึก logs, แสดงผล,


Code:
http://www.itmanage.info/technology/router/syslog/kiwi_syslog_server.html



Forward log to keyboard vb-script example by kiwi


Quote:
Function Main()

Dim objShell, MsgTxt, MsgHostAddress
Set objShell = CreateObject("WScript.Shell")
MsgTxt = Fields.VarRawMessageText
MsgHostAddress = Fields.VarPeerAddress
objShell.sendkeys MsgHostAddress & vbtab & MsgTxt
objShell.sendkeys "{ENTER}"

End Function



Basic Linux Command


[li][/list]
ls เอาไว้ดูว่าในโฟลเดอร์ที่เราอยู่มีอะไรบ้าง[/li]
[li]cd xxx เหมือน windows เข้าโฟลเดอร์[/li]
[li]cd .. ออกจากโฟลเดอร์[/li]
[li]./ filename เป็นการสั่ง run ไฟล์[/li]
[li]mkdir xxx สร้างโฟลเดอร์[/li]
[li]rmdir xxx ลบโฟลเดอร์[/li]
[li]rm xxx ลบไฟล์[/li]
[li]cp dir/file dir2/file copy จาก โฟลเดอร์ dir -> dir2[/li]
[li]nano filename สร้างไฟล์ใหม่หรือเปิดไฟล์ที่มีอยู่แล้ว เป็น text editor ตัวนึง[/li]
show cdp neighbor
./cdp x.x.x.x
Output = Local Intrfce -> Port ID Loopback Neighbor Device ID

cdp file


Quote:
#!/usr/bin/php



do1.sh file


Quote:
#!/usr/bin/expect
set ip [lrange $argv 0 0]
spawn telnet ${ip}
expect "Username:"
send "xxxn"
expect "Password:"
send "yyyn"
expect ">"
send "enablen"
expect "Password:"
send "yyyn"
expect "#"
send "ter len 0n"
expect "#"
send "show cdp neighborsn"
expect "#"
send "quitn"


show module
./showmod x.x.x.x
output =


Code:
WS-X6704-10GE TBM2417IWI
|___WS-F6700-DFC3CXL TBM2419L2K
RSP720-3CXL-GE KBF2356ANZ
|___7600-PFC3CXL KBF2356AEV
|___7600-MSFC4 KBF2356ACZ
WS-X6724-SFP TBM2417K38
|___WS-F6700-DFC3CXL TBM2419L2L



showmod file


Quote:
#!/usr/bin/php



do4.sh file


Quote:
#!/usr/bin/expect
set ip [lrange $argv 0 0]
spawn telnet ${ip}
expect "Username:"
send "xxxn"
expect "Password:"
send "yyyn"
expect ">"
send "enablen"
expect "Password:"
send "yyyn"
expect "#"
send "show modulen"
expect "#"
send "quitn"


show xxx/config Cisco by SecureCRT
Example show inventory


Code:
# $language = "VBScript" ' xxx.vbs
# $interface = "1.0"

'==========================================================================
' DATE : 26/10/2010
' UPDATED:
' Thank : Brian Desmond
'==========================================================================

Sub Main
Const username = "plawansai" ' Username to use for login
Const password = "rmutt" ' Password for corresponding user
Const loginPass = "rmutt" ' Password to use for password only login (aka no aaa new-model)

Const oldEnablePass = "rmutt" ' The current enable Password

Const DEVICE_FILE_PATH = "C:sh inv.txt" ' สั่งให้ไปอ่าน list ip จาก File ซึ่งอยู่ folder เดียวกับตัว script

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim fil
Set fil = fso_OpenTextFile(DEVICE_FILE_PATH)

Dim ip
Dim name
Dim protocol
Dim line
Dim cnxnString
While Not fil.AtEndOfStream
line = fil.ReadLine

name = Split(line, ";")(0)
ip = Split(line, ";")(1)
protocol = Split(line, ";")(2)

Select Case protocol
Case "Telnet"
cnxnString = "/TELNET " & ip & " 23"
Case "SSH2"
cnxnString = "/SSH2 /L " & username & " /PASSWORD " & password & " /C 3DES /M MD5 " & ip
Case "SSH1"
cnxnString = "/SSH1 /L " & username & " /PASSWORD " & password & " /C 3DES /M MD5 " & ip
End Select

'Connect By Telnet'
crt.Screen.Synchronous = True
crt.Session.Connect cnxnString
If protocol = "Telnet" Then
'Authentication by TACACS+'
Dim index
index = crt.Screen.WaitForStrings("Username:", "Password:")

If index = 1 Then
crt.Screen.Send username & vbCr
crt.Screen.WaitForString "Password:"
crt.Screen.Send password & vbCr
End If
End If

'Enable'
crt.Screen.WaitForString ">"
crt.Screen.Send "en" & vbCr
crt.Screen.WaitForString "Password:"
crt.Screen.Send oldEnablePass & vbCr

'Privilege Mode'
'crt.Screen.WaitForString "#"
'crt.Screen.Send "conf t" & vbCr
'crt.Screen.WaitForString "(config)#"

'***** Command Input *****'
crt.Screen.WaitForString "#" ' รอเครื่องหมาย #
crt.Screen.Send "sho inv" & vbCr ' ส่ง string sho inv
crt.Screen.WaitForString "#"

'***** Disconnect *****'
crt.Session.Disconnect
Wend

fil.Close
End Sub



sho inv.txt example


Code:
;10.5.0.1;Telnet
;10.5.0.2;Telnet



ตั้งเวลาให้ save config ใน router


Code:
crt.Screen.Send "conf t" & vbCr
crt.Screen.WaitForString "(config)#"
crt.Screen.Send "kron policy-list Backupcfg" & vbCr
crt.Screen.WaitForString "(config)#"
crt.Screen.Send "cli show run | redirect tftp://10.5.3.22/" & ip & ".cfg" & vbCr ' ได้ ip มาแล้วก็เอามาใช้ประโยชน์ซะ
crt.Screen.WaitForString "(config)#"
crt.Screen.Send "kron occurrence Backupcfg in 1:00:00 recurring" & vbCr ' ให้เก็บวันละครั้ง
crt.Screen.WaitForString "(config)#"
crt.Screen.Send "policy-list Backupcfg" & vbCr
crt.Screen.WaitForString "(config)#"
crt.Screen.Send "end" & vbCr
crt.Screen.WaitForString "#"


ตรวจสอบการทำงานของ kron
R1#show kron schedule


Cr: boonmeelive & P'Phong@AIT


วิธีทำให้ SecureCRT save session ลงไฟล์ auto

sccrt.gif



Credit: P'Pong@AIT


การเขียน Shell Script


Code:
http://www.vwin.co.th/document.php?node=5

bigeyes.gif
 

PlAwAnSaI

Administrator
Script for Configure Cisco Router & Switch by SecureCRT

http://upload.siamza.com/1744466

How to use:
  1. Open vbs file with Text Editor such as EditPlus.
  2. Change user and password (abc & bcd).
  3. Const DEVICE_FILE_PATH = "C:IP.txt" < Check this line for txt file path.
  4. Change the send & wait string depend which you want:
    crt.Screen.Send "access-list 1 permit 10.122.99.0 0.0.0.255" & vbCr
    crt.Screen.WaitForString "(config)#"
  5. Open the IP.txt and change the IP Address.
  6. Open SecureCRT > Script > Run...your vbs file.
 
Top