Hey i have tried to make a simple script that can log in and send commands to the host/server:
Sub Main
crt.Screen.Synchronous = True
crt.Session.Connect "ip adress"
crt.Screen.WaitForString "Username: "
crt.Screen.Send "username" & chr(13)
crt.Screen.WaitForString "Password: "
crt.Screen.Send "password" & chr(13)
crt.Screen.Send "?" & chr(13)
crt.Screen.Synchronous = False
End Sub
my problem is it wont send anything.
Its working now:
Sub Main
host = Array("host1", "host2")
For each item in host
Dim user
user = "Username"
Dim passwd
passwd = "password"
cmd = "/SSH2 /L " & user & " /PASSWORD " & passwd & " /C AES-192-CTR /M SHA2-256 " & item
crt.Session.Connect cmd
Dim tab, index, nTabCount
nTabCount = crt.GetTabCount()
for index = 1 to nTabCount
set tab = crt.GetTab(index)
tab.activate
tab.screen.send "command" & vbcr
crt.Sleep 5000
crt.Session.Disconnect()
next
Next
End Sub
Related
I am using a vbscript via Secure CRT, containing different subs as well as global variables, outside the main sub, in order to be available for the subs.
I would like to ask if there is a way of exiting the script at any point desired, before reaching the end of the process and without using crt.Quit, because it would be better to have secure crt running and available for additional commands.
My sript is as follows
Intro = msgbox ("ONLY FOR AUTHORISED USE!!!", 1+16+0+4096)
If Intro =2 Then
MsgBox"Operation Cancelled"
ThisIsTheEnd
End If
DSLAM=inputbox ("Please Enter Dslam Name","Login")
If DSLAM="" Then
MsgBox"Operation Cancelled"
ThisIsTheEnd
End If
crt.Screen.Send "telnet " & DSLAM & Chr(13)
crt.Screen.WaitForString "login:"
crt.Screen.Send "xxxx" & Chr(13)
crt.Screen.WaitForString "Password:"
crt.Screen.Send "xxxxxxxx" & Chr(13)
crt.Screen.WaitForString ">"
crt.Screen.Send "enable" & Chr(13)
crt.Screen.WaitForString "Password:"
crt.Screen.Send "xxxxxxxx" & Chr(13)
crt.Screen.WaitForString "#"
crt.Screen.Send "conf t" & Chr(13)
crt.Screen.WaitForString "(config)#"
crt.Screen.Send "br" & Chr(13)
crt.Screen.WaitForString "#"
CARD=inputbox("Please Enter Dslam Card", "Dslam Card")
If Card="" Then
MsgBox"Operation Cancelled"
crt.Screen.Send "end" & Chr(13)
crt.sleep 500
crt.Screen.Send "exit" & Chr(13)
ThisIsTheEnd
End If
PORT=inputbox("Please Enter Dslam Port", "Dslam Port")
If Port="" Then
MsgBox"Operation Cancelled"
crt.Screen.Send "end" & Chr(13)
crt.sleep 500
crt.Screen.Send "exit" & Chr(13)
ThisIsTheEnd
End If
Sub Main()
Profile
NextAction
ThisIsTheEnd
End Sub
Sub Profile
SELPROFILE=inputbox("1.free_VDSL_8B_Default" & Chr(13) & "2.free_VDSL_12A" & Chr(13) & "3.free_VDSL_17A", "Please Select the Profile")
crt.Screen.Send "port lre" & " " & CARD & "/" & PORT & " disable" & Chr(13)
crt.sleep 500
If SELPROFILE=1 Then
MsgBox "Default 8B Profile Selected"
crt.Screen.Send "lre" & " " & CARD & "/" & PORT & " xdsl line-config free_VDSL_8B_Default" & Chr(13)
ElseIf SELPROFILE=2 Then
MsgBox "12A Profile Selected"
crt.Screen.Send "lre" & " " & CARD & "/" & PORT & " xdsl line-config free_VDSL_12A" & Chr(13)
ElseIf SELPROFILE=3 Then
MsgBox "17A Profile Selected"
crt.Screen.Send "lre" & " " & CARD & "/" & PORT & " xdsl line-config free_VDSL_17A" & Chr(13)
ElseIf SELPROFILE<>1 or 2 or 3 Then
MsgBox "INVALID PROFILE!!!", 0+16+0+4096
Profile
End If
crt.sleep 500
crt.Screen.Send "port lre" & " " & CARD & "/" & PORT & " enable" & Chr(13)
crt.sleep 500
crt.Screen.Send "end" & Chr(13)
crt.sleep 500
crt.Screen.Send "wr mem" & Chr(13)
crt.Screen.WaitForString "#"
End Sub
Sub NextAction
GOON=inputbox("1.Exit" & Chr(13) & "2.Show Sync" & Chr(13) & "3.Repeat", "Please select next action")
if GOON=1 then
crt.Screen.Send "exit" & Chr(13)
ElseIf GOON=2 then
crt.Screen.Send "sho lre" & " " & CARD & "/" & PORT & " xdsl phys-table linerates" & Chr(13)
NextAction
ElseIf GOON=3 then
crt.Screen.Send "conf t" & Chr(13)
crt.Screen.WaitForString "(config)#"
crt.Screen.Send "br" & Chr(13)
crt.Screen.WaitForString "#"
Profile
Else MsgBox "INVALID SELECTION!!!", 0+16+0+4096
NextAction
End if
End Sub
Sub ThisIsTheEnd
MsgBox"Thank you, come again"
crt.Quit
End Sub
So to summarize everything up, I want to have the option of exiting the script at the various message-input boxes stages, via the cancel option and without closing Secure CRT.
The whole script has to run through Secure CRT so the WScript.Quit is not an option.
Thank you for your time!
So the problem was finally solved by a declaring globally the variables used on the subs, adding a Do Until Loop and rearranging the subs in order that the script can end with the Exit and End Sub commands.
Looks like the End Sub (when used correctly) is enough for terminating the script at any point desired.
I am using SecureCRT and want to run a vbs script while I am connected in a session, I want to get a site name from user by prompt and then use this variable inside a specific command (pmxh is a session specific command) to send this command to the session, here is my code but I don't know why my echo is not working and returning error (i just want to send pmxh command to the terminal that I have an already open session in it)
Sub Main()
' Prompt the end user for data
strAnswer = InputBox("Please enter site Name:")
' Check to see if the user provided any data, or canceled.
If strAnswer = "" Then
MsgBox "Canceled."
Exit Sub
End If
wscript.echo("pmxh strAnswer -m 0.25 -a pmTotNoRrcConnectReq")
End Sub
I believe you are looking for the crt.Screen.Send command.
crt.Screen.Synchronous = True
' This automatically generated script may need to be
' edited in order to work correctly.
Sub Main()
crt.Screen.Send "cd vshell" & chr(9) & chr(13)
crt.Screen.WaitForString "$ "
crt.Screen.Send "ls" & chr(13)
crt.Screen.WaitForString "$ "
crt.Screen.Send "rpm -U vshell-3.5.0-3" & chr(9) & chr(13)
crt.Screen.WaitForString "$ "
crt.Screen.Send "telnet localhost 22" & chr(13)
crt.Screen.Send chr(13)
End Sub
Read more on sending commands to the terminal -> here (page 10)
I need to write a diagnostic utility in VBS which i will package in my windows application installer.
I want the utility to run silently when the user is installing the application.
I tried:
Set pingCXS = objShell.Run("tracert -h 9 webaddress", 0, True)
Set pingCXSOutput = pingCXS.StdOut
strpingCXSOutput = pingCXSOutput.ReadAll
but it returns only the error code not the whole ping information.
When i use run method it gives a command window pop up:
Any other method to traceRT the webaddress without windows popup?
Also using a batch file is not a good option for me, as i have to use some WMI queries in the utility, which will require admin rights in batch file...
Please help out
Try this code :
Option Explicit
Dim ws,fso,TmpLogFile,Logfile,MyCmd,Webaddress,Param
Set ws = CreateObject("wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
TmpLogFile = "TmpFile.txt"
LogFile = Left(Wscript.ScriptFullName,InstrRev(Wscript.ScriptFullName, ".")) & "log"
If fso.FileExists(LogFile) Then fso.DeleteFile LogFile
webaddress = "www.stackoverflow.com"
Param = "-h 9"
MyCmd = "Tracert " & Param & " " & Webaddress & " >> "& TmpLogFile &_
" & cmd /U /C Type " & TmpLogFile & " > " & LogFile & " & Del " & TmpLogFile & ""
Call Run(MyCmd,0,True)
ws.run LogFile
'**********************************************************************************************
Function Run(StrCmd,Console,bWaitOnReturn)
Dim ws,MyCmd,Result
Set ws = CreateObject("wscript.Shell")
'A value of 0 to hide the MS-DOS console
If Console = 0 Then
MyCmd = "CMD /C " & StrCmd & ""
Result = ws.run(MyCmd,Console,bWaitOnReturn)
If Result = 0 Then
MsgBox "Success"
Else
MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
End If
End If
'A value of 1 to show the MS-DOS console
If Console = 1 Then
MyCmd = "CMD /K " & StrCmd & ""
Result = ws.run(MyCmd,Console,bWaitOnReturn)
If Result = 0 Then
MsgBox "Success"
Else
MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
End If
End If
Run = Result
End Function
I have a vbs code like:
Message4 = "Please enter Check Out Path"
Title4 = "Check Out Path "
variable1 = InputBox(Message4, Title4,"", 4500, 4500)
Message5 = "Please enter SVN URL"
Title5 = "SVN URL "
variable2 = InputBox(Message5, Title5, "", 4500, 4500)
Folder\batchfile.bat"""
objWshell.Run "batxhfile.bat"
and also batch file named batchfile.bat
#echo off
Color 42
echo. [ SVN Updater ]
set Checkout_path=checkout path
set SVN=C:\Program Files\TortoiseSVN\bin
set svn_url=SVN path
echo. Updating %Checkout_path% to SVN...
"%SVN%\TortoiseProc.exe" /command:checkout /url:"%svn_url%" /path:"%Checkout_path%" /closeonend:2
echo. done.
echo.
echo. Operation complete.
Now i want to pass the value of variable1 and variable2 from vbs code to batch file in the place of checkout path and svn path i have tried lots of method but no success uptill plz help.
I agree why you wouldn't simply call 'TortoiseProc.exe' from a VBS, however you may have you reasons for calling via a batch script. Simply pass arguments into a batch from a VBS:
`Const ERR_SUCCESS = 0
Const BAT_SCRIPT = "<folder>\batchfile.bat"
Dim oWSH, sCmd, iRC, sVar1, sVar2
Set oWSH = WScipt.CreateObjects("WScript.Shell")
Do While sVar1 <> ""
sVar1 = InputBox("Please enter Check Out Path", "Check Out Path", 4500, 4500)
Loop
Do While sVar2 <> ""
sVar2 = InputBox("Please enter SVN URL", "SVN URL", 4500, 4500)
Loop
sCmd = "cmd.exe /c """ & BAT_SCRIPT & "" "" & sVar1 & "" "" & sVar2 & """"
WScript.Echo "COMMAND: sCmd"
On Error Resume Next
iRC = oWSH.Run(sCmd, 0, True)
If iRC <> ERR_SUCCESS And Err.Number <> ERR_SUCCESS Then
MsgBox "ERROR: [" & Err.Source & "] " & CStr(Err.Number) & " - " & Err.Description & vbCrLf & _
" '" & BAT_SCRIPT "' return code = '" & CStr(iRC) & "' from command:" & vbCrLf & _
" COMMAND: " & sCmd, vbOkOnly, "Batch Script Error"
End If
Err.Clear
Set oWSH = Nothing`
You're result batch script command should be called like the following:
cmd.exe /c "<folder>\batchfile.bat" "<var1>" "<var2>"
Ensure your batch script gathers arguments, removes string double quotes and validates correctly:
`set Checkout_path=%1
set Checkout_path=%Checkout_path:~1,-1%
set svn_url=%2
set svn_url=%svn_url:~1,-1%
if /i "%Checkout_path%" ne "" (
exit /b 99
)
if /i "%svn_url%" ne "" (
exit /b 99
)`
Hope this helps ;)
I am trying to write a script where it will prompt you for a hostname, say 222012-DC01 from this it will resolve the ip address from dns via ping or nslookup.
It should then modify the ip address to ping the router for that site. If the ip address was 10.123.2.1 it should ping 10.123.1.1 for the router for that site.
The script should give you an output of server offline or router offline.
Work in an enviroment looking after several hundred sites, we take ownership of servers but not network incidents such as a router failure.
Your help is much appreciated...
In the future please post what you have got and tried.
Here is a tested script
function get_ip(strTarget)
set objShell = CreateObject("WScript.Shell")
set objExec = objShell.Exec("ping -n 2 -w 1000 " & strTarget)
strPingResults = LCase(objExec.StdOut.ReadAll)
get_ip = ""
if InStr(strPingResults, "reply from") then
wscript.echo VbCrLf & strTarget & " responded to ping."
set regEx = New RegExp
regEx.Pattern = "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"
set matches = regEx.Execute(strPingResults)
if matches.count > 0 then
get_ip = matches(0)
end if
else
wscript.echo vbCrLf & strTarget & " did not respond to ping."
wscript.quit 1
end If
end function
function is_online(strTarget)
set objShell = CreateObject("WScript.Shell")
set objExec = objShell.Exec("ping -n 2 -w 1000 " & strTarget)
strPingResults = LCase(objExec.StdOut.ReadAll)
if inStr(strPingResults, "reply from") then
is_online = true
else
is_online = false
end If
end function
pcname = inputbox( "Give the pc-name to ping:")
ip = get_ip(pcname)
wscript.echo "ip of pc " & pcname & " is " & ip
aIp = split(ip, ".")
aIp(2) = 1
router = join(aIp, ".")
wscript.echo "pinging " & router
if is_online(strTarget) then
wscript.echo "router is online"
else
wscript.echo "router is offline"
end if