Sub write_to_file()
Open "E:\work\SRLab\script\SRLab.vbs" For Output As #1
Print #1, "# $language = ""VBScript"""; VBScript; Chr(10); ""; "# $interface = ""1.0"""; VBScript; Chr(10); "crt.Screen.Synchronous = True "; VBScript; Chr(10);
'Print #1, "Set conf = crt.OpenSessionConfiguration("135.240.146.101)")"
'Print #1, "tab0 = crt.session.Connectintab("""; ""; "/telnet 135.240.146.101 23"; ""; """)"
'Print #1, "/telnet 135.240.146.101 23 "
'Print #1, """)"
write_open_session
write_ip
write_ospf
write_mpls
write_main
Close #1
End Sub
Sub write_open_session()
Dim vHosts(100)
Dim i As Integer
Dim j As Byte
Dim logintype
Print #1, "Sub open_session () "; VBScript; Chr(10);
If Sheet1.Cells(2, 10) <> "" Then
logintype = Sheet1.Cells(2, 10)
Else
logintype = "telnet "
End If
For i = 1 To 6
vHosts(i) = Sheet1.Cells(i + 1, 8)
If logintype = "telnet" Then
Print #1, "Set "; "tab"; " = crt.session.Connectintab("""; "/s"; " "; vHosts(i); """)"
'Print #1, "tab.Screen.WaitForString ("""; "Login:"; """)"
'Print #1, "tab.Screen.Send """; "student """; " & Chr(13)"
'Print #1, "tab.Screen.WaitForString ("""; "Password:"; """)"
'Print #1, "tab.Screen.Send """; "student """; " & Chr(13)"
Else
Print #1, "Set "; "tab"; " = crt.session.Connectintab("""; "/"; logintype; " /L admin /PASSWORD admin "; vHosts(i); """)"
End If
Next
Print #1, "End Sub "; VBScript; Chr(10); VBScript; Chr(10);
End Sub
Sub write_main()
Print #1, VBScript; Chr(10);
Print #1, VBScript; Chr(10);
Print #1, "'======================================================"; VBScript; Chr(10);
Print #1, "'= ="; VBScript; Chr(10);
Print #1, "'= main script ="; VBScript; Chr(10);
Print #1, "'= ="; VBScript; Chr(10);
Print #1, "'======================================================"; VBScript; Chr(10);
Print #1, "Sub Main ()"; VBScript; Chr(10);
Print #1, " open_session"
Print #1, "crt.Sleep 15000"
Print #1, " ip_configure"
Print #1, "crt.Sleep 5000"
Print #1, " ospf_configure"
Print #1, "crt.Sleep 5000"
Print #1, " mpls_configure"
Print #1, "End Sub "; VBScript; Chr(10);
End Sub
Sub write_ip()
Dim row As Integer
Dim colom As Integer
Dim i, j
Dim pre_router
Print #1, VBScript; Chr(10);
Print #1, VBScript; Chr(10);
Print #1, "'======================================================"; VBScript; Chr(10);
Print #1, "'= ="; VBScript; Chr(10);
Print #1, "'= ip configure ="; VBScript; Chr(10);
Print #1, "'= ="; VBScript; Chr(10);
Print #1, "'======================================================"; VBScript; Chr(10);
Print #1, VBScript; Chr(10); "Sub ip_configure ()"; VBScript; Chr(10);
pre_router = "R0"
Print #1, "'begin to configure ip and port "
Print #1, "set tab = crt.GetTab(1)"
Print #1, "tab.activate"
For row = 19 To 200
'pre_router = "R1"
If Sheet1.Cells(row, 1) = "" Then
Exit For
End If
i = Right(Sheet1.Cells(row, 1), 1)
If Sheet1.Cells(2, 10) = "telnet" Then
i = i
Else
i = i
End If
If Sheet1.Cells(row, 1) <> pre_router Then
Print #1, "set tab = crt.GetTab("; i; ")"
Print #1, "tab.activate"
Print #1, "tab.Screen.Send """; "configure port 1/1/[1..10] no shu """; " & Chr(13)"
pre_router = Sheet1.Cells(row, 1)
End If
If Sheet1.Cells(row, 3) <> "" Then
Print #1, "tab.Screen.Send """; "config router interface "; Sheet1.Cells(row, 3); " address "; Sheet1.Cells(row, 4); "/30"""; " & Chr(13)"
Print #1, "tab.Screen.Send """; "config router interface "; Sheet1.Cells(row, 3); " port "; Sheet1.Cells(row, 2); """"; " & Chr(13)"
End If
Next
Print #1, "End Sub "; VBScript; Chr(10);
End Sub
Sub write_ospf()
Dim row As Integer
Dim colom As Integer
Dim i
Dim pre_router
Print #1, VBScript; Chr(10);
Print #1, VBScript; Chr(10);
Print #1, "'======================================================"; VBScript; Chr(10);
Print #1, "'= ="; VBScript; Chr(10);
Print #1, "'= ospf configure ="; VBScript; Chr(10);
Print #1, "'= ="; VBScript; Chr(10);
Print #1, "'======================================================"; VBScript; Chr(10);
Print #1, VBScript; Chr(10); "Sub ospf_configure ()"; VBScript; Chr(10);
pre_router = "R0"
Print #1, "'begin to configure ospf "
Print #1, "set tab = crt.GetTab(1)"
Print #1, "tab.activate"
For row = 19 To 200
'pre_router = "R1"
If Sheet1.Cells(row, 1) = "" Then
Exit For
End If
i = Right(Sheet1.Cells(row, 1), 1)
If Sheet1.Cells(2, 10) = "telnet" Then
i = i
Else
i = i
End If
If Sheet1.Cells(row, 1) <> pre_router Then
Print #1, "set tab = crt.GetTab("; i; ")"
Print #1, "tab.activate"
Print #1, "tab.Screen.Send """; "configure router ospf area 0 interface system"""; " & Chr(13)"
Print #1, "tab.Screen.Send """; "exit"""; " & Chr(13)"
pre_router = Sheet1.Cells(row, 1)
End If
If Sheet1.Cells(row, 5) = "ospf" Or Sheet1.Cells(row, 5) = "mpls&ospf" Then
Print #1, "tab.Screen.Send """; "configure router ospf area 0 interface "; Sheet1.Cells(row, 3); " interface-type point-to-point """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "exit"""; " & Chr(13)"
End If
Next
Print #1, "End Sub "; VBScript; Chr(10);
End Sub
Sub write_mpls()
Dim row As Integer
Dim colom As Integer
Dim i
Dim pre_router
Print #1, VBScript; Chr(10);
Print #1, VBScript; Chr(10);
Print #1, "'======================================================"; VBScript; Chr(10);
Print #1, "'= ="; VBScript; Chr(10);
Print #1, "'= mpls configure ="; VBScript; Chr(10);
Print #1, "'= ="; VBScript; Chr(10);
Print #1, "'======================================================"; VBScript; Chr(10);
Print #1, VBScript; Chr(10); "Sub mpls_configure ()"; VBScript; Chr(10);
pre_router = "R0"
Print #1, "'begin to configure mpls "
Print #1, "set tab = crt.GetTab(1)"
Print #1, "tab.activate"
For row = 19 To 200
'pre_router = "R1"
If Sheet1.Cells(row, 1) = "" Then
Exit For
End If
i = Right(Sheet1.Cells(row, 1), 1)
If Sheet1.Cells(2, 10) = "telnet" Then
i = i
Else
i = i
End If
If Sheet1.Cells(row, 1) <> pre_router Then
Print #1, "set tab = crt.GetTab("; i; ")"
Print #1, "tab.activate"
Print #1, "tab.Screen.Send """; "config router mpls """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "path loose """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "no shutdown """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "back """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "no shutdown """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "back """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "rsvp """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "no shutdown """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "exit """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "exit """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "configure router mpls interface system"""; " & Chr(13)"
Print #1, "tab.Screen.Send """; "back"""; " & Chr(13)"
pre_router = Sheet1.Cells(row, 1)
End If
If Sheet1.Cells(row, 5) = "mpls" Or Sheet1.Cells(row, 5) = "mpls&ospf" Then
Print #1, "tab.Screen.Send """; "config router mpls """; " & Chr(13)"
Print #1, "tab.Screen.Send """; " interface "; Sheet1.Cells(row, 3); """"; " & Chr(13) "
Print #1, "tab.Screen.Send """; "back """; " & Chr(13)"
End If
Next
'configure lsp
pre_router = "R0"
For row = 19 To 200
'
If Sheet1.Cells(row, 1) = "" Then
Exit For
End If
i = Right(Sheet1.Cells(row, 1), 1)
If Sheet1.Cells(row, 1) <> pre_router Then
Print #1, "set tab = crt.GetTab("; i; ")"
Print #1, "tab.activate"
pre_router = Sheet1.Cells(row, 1)
End If
If Sheet1.Cells(row, 5) = "mpls" Or Sheet1.Cells(row, 5) = "mpls&ospf" Then
Print #1, "tab.Screen.Send """; "config router mpls """; " & Chr(13)"
Print #1, "tab.Screen.Send """; " lsp "; Right(Sheet1.Cells(row, 3), Len(Sheet1.Cells(row, 3)) - 4); """"; " & Chr(13) "
Print #1, "tab.Screen.Send """; "to 10.10.10."; Right(Sheet1.Cells(row, 3), 1); """"; " & Chr(13)"
Print #1, "tab.Screen.Send """; "primary loose """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "exit """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "no shutdown """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "exit """; " & Chr(13)"
Print #1, "tab.Screen.Send """; "exit """; " & Chr(13)"
End If
Next
Print #1, "End Sub "; VBScript; Chr(10);
End Sub
Sub open_session()
Dim vHosts(100)
Dim table(100)
Dim i As Integer
vHosts(0) = "135.240.146.101"
vHosts(1) = "135.240.146.102"
vHosts(2) = "135.240.146.105"
i = 1
For Each strHost In vHosts
If strHost = "" Then Exit For
' Make sure we are disconnected before attempting a connection
'If crt.Session.Connected Then crt.Session.Disconnect
' Connect to the next host
'crt.Session.Connect "/SSH2 /L user /PASSWORD p4$$w0rd " & strHost
crt.Session.Connectintab "/SSH2 /L admin /PASSWORD admin " & strHost
' Do work on the remote machine.
'The Disconnect() action is done at the top of the loop (in the event
' that the tab in which this script is launched already has an
' active connection).
Next
For i = 1 To 3
'set tab = crt.GetTab(i)
'tab.activate
'Name = tab.Caption
'MsgBox Name
'tab.Screen.Send "configure port 1/1/[1..10] no shu" & chr(13)
Next
'Set conf = crt.OpenSessionConfiguration("192.168.188.165")
'Set tab1 = conf.ConnectInTab()
'tab1.Screen.WaitForString ("Login:")
'tab1.Screen.Send "admin" & Chr(13)
'tab1.Screen.WaitForString ("Password:")
'tab1.Screen.Send "admin" & Chr(13)
'tab1.Screen.Send "show route interface" & Chr(13)
End Sub
Sub vbtest()
Dim tabe(100)
Dim i
For i = 0 To 6
tabe(i) = i
i = i + 1
Next
End Sub
Sub write_ip1()
Dim row As Integer
Dim colom As Integer
Dim i
Dim pre_router
Print #1, "Sub ip_configure ()"; VBScript; Chr(10);
For colom = 10 To 15
pre_router = "R1"
Print #1, "set tab = crt.GetTab(1)"
Print #1, "tab.activate"
For row = 19 To 200
'pre_router = "R1"
If Sheet1.Cells(row, 1) = "" Then
Exit For
End If
If Sheet1.Cells(row, colom) <> "" Then
i = Right(Sheet1.Cells(row, 1), 1)
If Sheet1.Cells(row, 1) <> pre_router Then
Print #1, "set tab = crt.GetTab("; i; ")"
Print #1, "tab.activate"
pre_router = Sheet1.Cells(row, 1)
End If
Print #1, "tab.Screen.Send """; Sheet1.Cells(row, colom); """"; "& chr(13)"
End If
Next
Next
Print #1, "End Sub "; VBScript; Chr(10);
End Sub