📜 ⬆️ ⬇️

Better to lose a day, and then teleport wherever you want and how much you want

Do you use SecureCRT in your work? Many times a day do you have to go to different equipment in one or several spaces of IP addresses that differ only in one or two terminal octets and perform typical tasks on them? Login password to access the equipment in your network represented by one or two combinations? Have you thought a lot about how to make it all happen on your own, but were afraid to ask? Or just want to briefly find out what, in principle, can be made a script on SecureCRT? And so, SecureCRT + VBScript or "creativity in the routine." Welcome under cat.

Who i am and what i do


I am a junior in a provider company, my duties include helpdesc second line and many routine tasks like pushing Vlan from port to port through the entire network, or supplying other services to the end port of the subscriber, setting up different pieces of hardware aggregation and distribution for placing on the network. But whatever routine tasks of organizing new channels or setting up pieces of iron are the most inconvenient and distracting routine, these are contacts with helpdesk, which are always reduced to viewing port status, the presence of poppy on it, and the necessary Vlan, number of errors and history of UP / Down from equipment logs in rare cases.

How it all began


The more time passed from the moment of my employment, the faster my routine tasks were solved by me and the more they bored me. And at a certain moment I decided to try to simplify my life and throw off the routine of the algorithms. As a result, somewhere in half a year of unhurried work, I had several scripts, which I would like to share with you. In addition, I searched for Habra and Stack Overflow and came to the conclusion that nowhere else such a topic has been raised. Taking into account how much profit my workload brings me daily (saving time from a minute to 15 for an application from helpdesk) it seemed to me very strange.

What I want to share


In this post we will discuss the most recent of my creation. It is written as competently as possible and with an eye for easy finishing, it is easy to understand and change to fit your needs. The fact is that, not being a programmer, I wrote everything solely on the principle of “if only it worked” and only with time as I wrote I learned (or are just beginning to “learn”) to write programs at least a little bit correctly.
')

Description of work:


This script requires you to enter a part of the IP address of the equipment (for example, in my network all devices have an address of 10.150.XX.XXX or 172.100.100.XXX) and a port.



Thus, there is no need to remember what is behind a dozen open tabs, because there is now not just an IP address, but also a device name.


At the end, he displays a message with everything he learned.

List and types of equipment with which the script works: | ZTE | HP | QTECH | H3C | Quidway-EA | Quidway-EI |


Pro updates


Since my colleagues also use my work, and I often add or improve it, I also wrote a small update module that should be located in an accessible network location next to the new version of this script. The path to the update module is specified in the script header itself in the UpdateEngine variable. The same path is the path to the new version.
The update occurs when the Update command is entered in the IP address field. If you enter Upload, the new version will be shipped from the local computer to the server.

Almost end


In the process of writing, I encountered several unobvious difficulties, so if you have any questions, ask.
Further, the actual code of both scripts. Please use, change to fit your needs. Perhaps for someone my experience will serve as the initial impulse to automate my own routine. Someone will see examples of the use of VBScript in SecureCRT, someone will raise the CSW, noticing the dampness in the code. In any case, I am sure that the topic will be useful to many.
I advise you to edit the script in Notepad ++. it uses such formatting that allows Notepad ++ to collapse individual modules (hide lines) so as to facilitate navigation through the code. Unneeded at the moment modules can be minimized to two lines - the beginning and the end.
I do not pretend to be the programmer of the year, so for dampness and bearish moves (inelegant solutions), please do not kick, but I will be happy for future tips.
Code relevant for SecureCRT ver 7.0.1

Almost 300 lines of the first script:
Script
#$language = "VBScript" #$interface = "1.0" crt.Screen.Synchronous = True crt.screen.IgnoreEscape = True scr_ver = "0,55" Developer = False UpdateEngine = "\\SERVER\Script\Script_Update.vbs" ' Change Log: ' v0.1 The very beggining. Here where it starts. ' v0.2 16.01.14   Login2  ZTE ' v0.3 16.01.14       ' v0.4 20.01.14       Description '---v0.5 22.01.14   ,  IP  Caption . ' v0.51 24.01.14  +IP -    . ' v0.53 24.01.14     . ' v0.54 24.01.14        "-" ' v0.55 24.01.14     Dim ip 'IP   'ip = "10.150.127.245" 'H3C S3100-8TP-EI  Description        'ip = "10.150.226.246" 'H3C S3100-26TP-EI 1/0/1 'ip = "10.150.210.26" 'Quidway S2016TP-EA 'ip = "10.150.119.69" '[Quidway S2309TP-EI] 0/0/1 ---------------------------------------------- 'ip = "10.150.218.16" '[Quidway S2309TP-EI] 0/0/1 'ip = "10.150.226.33" 'ZTE ZXR10 2928E 'ip = "10.150.211.224" 'Qtech Dim Login Dim Passw Dim SW_Name Dim Port 'Port = "1" Dim Port_State Port_State = "UP" Dim Port_Description Dim Mac Dim exit_ '   "1"     Dim Equipment_ID '   | ZTE | QTECH | H3C | Quidway-EA | Quidway-EI | Dim Uptime Dim Oblast Oblast = False Dim var, var2, test Dim objCurrentTab, Tab Sub Update(file) Dim fso, f Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile(file, 1) str = f.ReadAll f.Close ExecuteGlobal(str) End Sub Sub User() '   - Login1 Login2 'if objCurrentTab.Dialog.MessageBox (var,"Login1", 32 Or 4 Or 0 ) = 6 then ' 6  Login1, 7  Login2 Login = "Login1" Passw = "Pass1" 'else ' Login = "Login2" ' Passw = "Pass2" 'end if End sub Sub Connect() ' ,     ,    ,   IP = crt.Dialog.Prompt(" IP  10.150.", "sublime habr_script ver_" & scr_ver, "", False) '  IP  if ip = "Update" then call Update (UpdateEngine) msgbox "    ." , 0 , "sublime habr_script ver_" & scr_ver exit sub elseif ip = "Upload" then Developer = True call Update (UpdateEngine) msgbox "  ,  ", 0 , "sublime habr_script ver_" & scr_ver exit sub elseif ip = "" then msgbox "IP   " , 0 , "sublime habr_script ver_" & scr_ver exit_ = 1 exit sub end if Port = crt.Dialog.Prompt("  ", "sublime habr_script ver_" & scr_ver, "", False) '    If Left(IP, 1) = "-" and Left(IP, 1) <> "" then ' .     IP = Mid(IP, 2, Len(IP)) if crt.Session.Connected then crt.Session.Disconnect '    -  crt.session.Connect "/telnet " & chr(34) & "10.150." & ip & chr(34) & " 23" , , true '  Set objCurrentTab = crt.GetScriptTab if not objCurrentTab.Session.Connected then msgbox "  " exit_ = 1 exit sub else 'msgbox " " end if elseif Left(IP, 1) = "+" and Left(IP, 1) <> "" then ' +    Oblast = true IP = Mid(IP, 2, Len(IP)) set Tab = crt.session.ConnectInTab ("/telnet " & chr(34) & "172.100.100." & ip & chr(34) & " 23" , , true ) '  tab.Screen.Synchronous = True ' , ! tab.screen.IgnoreEscape = True ' , ! 'msgbox "before Set objCurrentTab = crt.GetTab(tab.Index)" Set objCurrentTab = crt.GetTab(tab.Index) if not objCurrentTab.Session.Connected then msgbox "  " exit_ = 1 exit sub else 'msgbox " " & exit_ end if else '     . 'msgbox "before set Tab = crt.session.ConnectInTab" set Tab = crt.session.ConnectInTab ("/telnet " & chr(34) & "10.150." & ip & chr(34) & " 23" , , true ) '  tab.Screen.Synchronous = True ' , ! tab.screen.IgnoreEscape = True ' , ! 'msgbox "before Set objCurrentTab = crt.GetTab(tab.Index)" Set objCurrentTab = crt.GetTab(tab.Index) if not objCurrentTab.Session.Connected then msgbox "  " exit_ = 1 exit sub else 'msgbox " " & exit_ end if end if objCurrentTab.Screen.Synchronous = True objCurrentTab.screen.IgnoreEscape = True End Sub Sub LogOn() '  objCurrentTab.Screen.WaitForStrings "Username:", "login", 10 if Oblast = False then objCurrentTab.Screen.Send "Login1" + chr(13) end if objCurrentTab.Screen.WaitForString "assword:", 10 if Oblast = False then objCurrentTab.Screen.Send "Pass1" + chr(13) end if var = CStr(objCurrentTab.screen.WaitForStrings(">", "#", "Username:", "login", 10)) 'msgbox var if var = 0 then msgbox " " exit_ = 1 exit sub elseif ((var = 3) or (var = 4)) and (Oblast = false) then if objCurrentTab.Screen.WaitForString ("authentication success", 1) = false then '   zte 'msgbox "ZTE" objCurrentTab.Screen.Send "Login2" + chr(13) objCurrentTab.Screen.WaitForString "assword:" objCurrentTab.Screen.Send "Pass2" + chr(13) end if elseif (var = 3 or var = 4) and Oblast = true then objCurrentTab.Screen.WaitForString "assword:", 10 end if objCurrentTab.Screen.Send chr(13) if CStr(objCurrentTab.screen.WaitForStrings(">", "#", 2)) = 0 then msgbox " " exit_ = 1 exit sub end if End sub Sub Equipment() ' ,    objCurrentTab.Screen.Send " " & chr(13) objCurrentTab.screen.WaitForString chr(10) SW_Name = objCurrentTab.Screen.ReadString (">", "#", 1) if SW_Name <> "" then '     SW_Name if left(SW_Name,1) = "<" then SW_Name = Mid(SW_Name, 2, Len(SW_Name)) end if objCurrentTab.Caption = IP & "_" & SW_Name end if if Oblast = true then '        172.100.100. exit_ = 1 exit sub end if if port <> "" then objCurrentTab.Screen.Send "display version" & chr(13) ' 1 2 3 4 5 6 0 var = CStr(objCurrentTab.screen.WaitForStrings("Quidway", "H3C", "HP", "QTECH", "Invalid", "ommand", 2)) if var = 0 then msgbox "   . ." exit_ = 1 exit sub elseif (var = 5 or var = 6) then objCurrentTab.Screen.Send "show version" & chr(13) ' 1 2 3 4 0 var = CStr(objCurrentTab.screen.WaitForStrings("ZTE", "QTECH", "Invalid", "ommand", 1)) if (var = 0) or (var = 3) or (var = 4) then msgbox "   . ." exit_ = 1 exit sub elseif var = 1 then Equipment_ID = "ZTE" elseif var = 2 then Equipment_ID = "QTECH" Port = "1/" & Port end if elseif (var = 2) or (var = 3) then Equipment_ID = "H3C" Port = "1/0/" & Port elseif var = 1 then objCurrentTab.screen.WaitForString " " var = CStr(objCurrentTab.screen.WaitForStrings("-EA", "-EI", 2)) if var = 0 then msgbox "   . ." exit_ = 1 exit sub elseif (var = 1) then Equipment_ID = "Quidway-EA" Port = "1/0/" & Port elseif (var = 2) then Equipment_ID = "Quidway-EI" Port = "0/0/" & Port end if end if objCurrentTab.screen.WaitForString "ptime" Uptime = objCurrentTab.Screen.ReadString(chr(13) , 1) objCurrentTab.screen.WaitForStrings ">", "#", 1 end if End sub Sub Port_Information() '    - State, Description if Equipment_ID = "ZTE" then ' ZTE objCurrentTab.Screen.Send chr(13) objCurrentTab.screen.WaitForString ">" objCurrentTab.Screen.Send "show port " & Port & " brief" & chr(13) var = CStr(objCurrentTab.screen.WaitForStrings("up", "down", 2)) if var = 0 then msgbox "   . ." exit_ = 1 exit sub elseif (var = 1) then Port_State = "UP" elseif (var = 2) then Port_State = "DOWN" end if Port_Description = Trim(objCurrentTab.Screen.ReadString(chr(13) , 2)) end if '/ZTE '-------------------------------------------------------------------- if Equipment_ID = "H3C" or Equipment_ID = "Quidway-EA" or Equipment_ID = "Quidway-EI" then ' H3C or Quidway-EA or Quidway-EI objCurrentTab.Screen.Send chr(13) objCurrentTab.screen.WaitForString ">" objCurrentTab.Screen.Send "display interface Ethernet " & Port & chr(13) var = CStr(objCurrentTab.screen.WaitForStrings("UP", "DOWN", 2)) if var = 0 then msgbox "   . ." exit_ = 1 exit sub elseif (var = 1) then Port_State = "UP" elseif (var = 2) then Port_State = "DOWN" end if objCurrentTab.Screen.Send " " & chr(13) objCurrentTab.screen.WaitForString ">", 1 objCurrentTab.Screen.Send " " & chr(13) objCurrentTab.screen.WaitForString ">", 1 objCurrentTab.Screen.Send "display current-configuration interface Ethernet " & Port & chr(13) objCurrentTab.screen.WaitForString "description", 1 Port_Description = Trim(objCurrentTab.Screen.ReadString(chr(13) , 2)) end if '/H3C or Quidway-EA or Quidway-EI '-------------------------------------------------------------------- if Equipment_ID = "QTECH" then ' QTECH objCurrentTab.Screen.Send chr(13) objCurrentTab.screen.WaitForString "#" objCurrentTab.Screen.Send "show interface ethernet " & Port & chr(13) var = CStr(objCurrentTab.screen.WaitForStrings("up", "down", 2)) if var = 0 then msgbox "   . ." exit_ = 1 exit sub elseif (var = 1) then Port_State = "UP" elseif (var = 2) then Port_State = "DOWN" end if objCurrentTab.Screen.Send " " & chr(13) objCurrentTab.screen.WaitForString "#" objCurrentTab.Screen.Send "show running-config interface ethernet " &Port & chr(13) objCurrentTab.screen.WaitForString "description", 1 Port_Description = Trim(objCurrentTab.Screen.ReadString(chr(13) , 2)) end if '/QTECH if Port_Description <> "" then '     Port_Description objCurrentTab.Caption = IP & "_" & Port_Description end if End sub Sub MacInformation() '   if Equipment_ID = "ZTE" then ' ZTE objCurrentTab.Screen.Send chr(13) objCurrentTab.screen.WaitForString ">" objCurrentTab.Screen.Send "show mac dynamic port " & Port & chr(13) objCurrentTab.screen.WaitForString "---" & chr(13) , 3 '     While var2 <> "stop" var = CStr(objCurrentTab.screen.WaitForStrings ("No MAC", chr(10), "Press", ">", 1)) 'msgbox var if var = 1 then Mac = "No Mac" elseif var = 2 then Mac = Mac & chr(13) & objCurrentTab.Screen.ReadString(" ", 1) Elseif var = 3 then objCurrentTab.Screen.Send " " for i = 1 to 98 objCurrentTab.screen.WaitForString chr(8), 1 next Mac = Mac & chr(13) & objCurrentTab.Screen.ReadString(" ", 1) Elseif var = 4 then var2 = "stop" Elseif var = 0 then var2 = "stop" end if objCurrentTab.screen.WaitForStrings chr(13), " ", 1 'var2 = objCurrentTab.Screen.ReadString(".", 1) ' var = "" ' for i = 1 to len(var2) ' test = Mid(var2, i, 1) ' 'msgbox test ' var = var & "|" & Asc(test) ' next ' msgbox "_..." & var & "..._" & "i= " & i & chr(13) & var2 wend end if '/ZTE if Equipment_ID = "H3C" or Equipment_ID = "Quidway-EA" then ' H3C or Quidway-EA objCurrentTab.Screen.Send chr(13) objCurrentTab.screen.WaitForString ">" objCurrentTab.Screen.Send "displ mac-address interface Ethernet " & port & chr(13) objCurrentTab.screen.WaitForString "TIME(s)", 1 While var2 <> "stop" var = CStr(objCurrentTab.screen.WaitForStrings ("No MAC", chr(10), "found", 1)) if var = 1 then Mac = "No Mac" elseif var = 2 then Mac = Mac & chr(13) & objCurrentTab.Screen.ReadString(" ", 1) elseif var = 3 then var2 = "stop" Elseif var = 0 then Mac = Mac & chr(13) & "more..." var2 = "stop" end if wend end if '/H3C or Quidway-EA if Equipment_ID = "Quidway-EI" then ' Quidway-EI objCurrentTab.Screen.Send chr(13) objCurrentTab.screen.WaitForString ">" objCurrentTab.Screen.Send "display mac-address dynamic Ethernet " & port & chr(13) objCurrentTab.screen.WaitForStrings "Lsp", "MAC-Tunnel", 5 objCurrentTab.screen.WaitForString "------------------------------------------------------" & chr(13), 3 While var2 <> "stop" var = CStr(objCurrentTab.screen.WaitForStrings ("displayed = 0", chr(10), "Total", 1)) if var = 1 then Mac = "No Mac" var2 = "stop" elseif var = 2 then var = objCurrentTab.Screen.ReadString(" ", 1) 'msgbox "_" & var & "_" if (var = chr(13) & chr(10) & "Total") or (var = chr(13) & chr(10) & "-------------------------------------------------------------------------------" & chr(13) & chr(10) & "Total") then var2 = "stop" else Mac = Mac & var & chr(13) end if objCurrentTab.screen.WaitForString chr(13), 1 elseif var = 3 then var2 = "stop" Elseif var = 0 then Mac = Mac & chr(13) & "more..." var2 = "stop" end if wend end if '/Quidway-EI if Equipment_ID = "QTECH" then ' QTECH objCurrentTab.Screen.Send chr(13) objCurrentTab.Screen.Send "show mac-address-table interface ethernet " & port & chr(13) objCurrentTab.screen.WaitForString "Read mac address table...." var = CStr(objCurrentTab.screen.WaitForStrings ("No mac", "---" & chr(13), 1)) if var = 1 then var2 = "stop" Mac = "No Mac" end if While var2 <> "stop" var = CStr(objCurrentTab.screen.WaitForStrings ( " ", SW_name, 1)) if var = 1 then Mac = Mac & chr(13) & Trim(objCurrentTab.Screen.ReadString(" ", 1)) objCurrentTab.screen.WaitForString chr(13) elseif var = 2 then var2 = "stop" Elseif var = 0 then Mac = Mac & chr(13) & "more..." var2 = "stop" end if wend end if End sub if exit_ <> 1 then Call User if exit_ <> 1 then Call Connect if exit_ <> 1 then Call LogOn if exit_ <> 1 then Call Equipment if exit_ <> 1 and Port <> "" then Call Port_Information if exit_ <> 1 and Port <> "" and Port_State = "UP" then Call MacInformation 'and Port_State = "UP" var = "  " & Equipment_ID & chr(13) & "Uptime " & Uptime & chr(13) var = var & " " & " = " & SW_Name & chr(13) var = var & "  " & Port & " = " & Port_State & chr(13) var = var & "  " & Port & " = " & Port_Description & chr(13) var = var & " : " & chr(13) & Mac & chr(13) var = var & "  " if Port <> "" then msgbox var end if 


And update script
Updateengine
 '#$language = "VBScript" '#$interface = "1.0" crt.Screen.Synchronous = True crt.screen.IgnoreEscape = True scr_vers = "0,1" ' Change Log: ' v0.1 21.01.14 The very beggining. Here where it starts. Dim cur_scr_path, cur_scr_Name, cur_scr_ver, cur_scr_file Dim ser_scr_path, ser_scr_Name, ser_scr_ver, ser_scr_file Sub CurrentScript() '   ,     cur_scr_path = crt.ScriptFullName For i = 1 to 10 if InStr(cur_scr_path,"\") = 0 then Exit for end if cur_scr_path = Right(cur_scr_path, Len(cur_scr_path) - InStr(cur_scr_path,"\")) next cur_scr_Name = cur_scr_path 'msgbox cur_scr_Name cur_scr_path = crt.ScriptFullName Set cur_scr_file = CreateObject("Scripting.FileSystemObject").OpenTextFile(cur_scr_path,1) ' 1 - for reading do while not cur_scr_file.AtEndOfStream cur_scr_ver = cur_scr_file.ReadLine cur_scr_ver = trim(cur_scr_ver) if left(cur_scr_ver, 10) = "scr_ver = " then cur_scr_ver = Mid (cur_scr_ver, 12, Len(cur_scr_ver) - 12)'Mid(cur_scr_ver, 11,InStr(cur_scr_ver," ")) 'msgbox cur_scr_ver = " & cur_scr_ver Exit do end if loop cur_scr_file.Close end sub Sub ServerScript() '   ,  ser_scr_path = "\\SERVER\Script" & "\" &cur_scr_Name 'msgbox ser_scr_path Set ser_scr_file = CreateObject("Scripting.FileSystemObject").OpenTextFile(ser_scr_path,1) ' 1 - for reading do while not ser_scr_file.AtEndOfStream ser_scr_ver = ser_scr_file.ReadLine ser_scr_ver = trim(ser_scr_ver) 'msgbox ser_scr_ver if left(ser_scr_ver, 10) = "scr_ver = " then ser_scr_ver = Mid (ser_scr_ver, 12, Len(ser_scr_ver) - 12) 'msgbox "ser_scr_ver = " & ser_scr_ver Exit do end if loop ser_scr_file.Close End sub Sub Comparisson() '  ,     . Const OverwriteExisting = True 'msgbox "_" & cur_scr_ver & "_" & ser_scr_ver& "_" 'MsgBox (TypeName(cur_scr_ver)) & "_" & (TypeName(ser_scr_ver)) If Developer = true then If CDbl(cur_scr_ver) < CDbl(ser_scr_ver) then '      msgbox "   . WTF?!",0 , "God mode ON." elseif CDbl(cur_scr_ver) = CDbl(ser_scr_ver) then '      msgbox "Version equals, nothing to do" ,0 , "God mode ON." elseif CDbl(cur_scr_ver) > CDbl(ser_scr_ver) then '        .   msgbox "Version difference, Uploading new version to the server. Press ok to begin" ,0 , "God mode ON." Set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.CopyFile cur_scr_path , ser_scr_path, OverwriteExisting end if elseif Developer = false then If CDbl(cur_scr_ver) < CDbl(ser_scr_ver) then '     .  . msgbox "  .  ." , 0 , "UpdateEngine" Set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.CopyFile ser_scr_path, cur_scr_path, OverwriteExisting elseif CDbl(cur_scr_ver) = CDbl(ser_scr_ver) then '      msgbox " .", 0 , "UpdateEngine" elseif CDbl(cur_scr_ver) > CDbl(ser_scr_ver) then '        . msgbox "   .", 0 , "UpdateEngine" end if end if Developer = false exit_ = 1 End sub Call CurrentScript() Call ServerScript() Call Comparisson() 



At last



I have another very useful script for GPON MA5680T hardware. Who faced, he knows how difficult it is to add services or to understand the current configuration of the terminal terminal, the so-called. "Ponky." I wrote a script that allows you to add services, display a list of services or parse a ponk from the GPONa configuration. The final table formed by the script looks like this

GPON
 : (6-0/1/1-2) ONT_name : UP : 92 C: 32303131B881F241 (2011-B881F241) __________________________ Service Port summury: ========================================================= |S*P | |Vlan| |Gem | |UV | |RTx | || Vlan desc --------------------------------------------------------- |5 | | 600| |130 | |2 | |5 | || Chanel1_name |38 | |1203| |136 | |3 | |7 | || |180 | |3563| |213 | |6 | |2 | || Chanel2_name |143 | |3786| |304 | |4 | |2 | || Chanel3_name |573 | | 598| |390 | |7 | |7 | || =========================================================  (O = UP; X = Down): ---------------------- [O] - Port 1 : 1,[2], [O] - Port 2 : 1,[3], [O] - Port 3 : 1,[4], [O] - Port 4 : 1,[6], [X] - Port 5 : 1,[7], ---------------------- ---------------------- Tcont_id 0.......1 Tcont_id 1.......12 Tcont_id 2.......5 Tcont_id 3.......57 Tcont : 4 ---------------------- 

Source: https://habr.com/ru/post/210822/


All Articles