How to stop sending username and password if mainserver not reachable

ganesh_6663

New Member
Joined
Jul 15, 2021
Messages
33
Office Version
  1. 2016
Platform
  1. Windows
Created tool to auto putty login into jumpserver first , from Jumpserver it will login into mainserver .
But some time mainserver is not reachable still script send username and password ......is their any way to stop sending username and password if mainserver not reachable ..

VBA Code:
Sub PUTTYSM()
Dim PuttyPID As Double
Dim PuttyHwnd As LongPtr
Dim serverName As String
Dim username As String
Dim password As String
Dim Jumpserver As Variant
Dim myserver As Variant
myserver = UserForm1.Reg2.Value
Jumpserver = UserForm1.Reg3.Value

 username = "demo"
 password = "password"
 mainserverpass = "password"

'Login jump server
PuttyPID = Shell("D:\putty.exe -ssh  " & Jumpserver, vbNormalFocus)   'CHANGE PATH TO .EXE
    PuttyHwnd = GetWindowHandle(CLng(PuttyPID))
    If PuttyHwnd <> 0 Then
   
   
        Application.Wait DateAdd("s", 2, Now)
        SendChars PuttyHwnd, username & vbCr
        Application.Wait DateAdd("s", 2, Now)
        SendChars PuttyHwnd, password & vbCr
        
    [B]'Login main server
        Application.Wait DateAdd("s", 1, Now)
        SendChars PuttyHwnd, "ssh demo@" & myserver & vbCr
        Application.Wait DateAdd("s", 1, Now)
        SendChars PuttyHwnd, mainserverpass & vbCr[/B]

    End If
   
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
you can use a combination/sequence of ping and telnet to check if the server is reachable and then if the required port is opened.
Then analyze the returned strings trying to figure out if you can connect or not.
However this may slow down things a bit ...
AFAIK putty uses SSH so the connection to the server is probably encrypted - what exactly are you worried about? Or is it that it goes out to putty as not encrypted characters?
Another way to do it would be to try and capture any windows/dialogs/message boxes with error messages putty will probably throw back at you if an operation fails.
 
Upvote 0
Really thanks for suggestion :)
If server not reachable still It is sending username and password , on putty window which is visible .
any way to analyze return string , if server is reachable ()able to ping)then only go forward to make connection(SSH) or stop.
Any suggestion......
 
Upvote 0
Really thanks for suggestion :)
If server not reachable still It is sending username and password , on putty window which is visible .
any way to analyze return string , if server is reachable ()able to ping)then only go forward to make connection(SSH) or stop.
Any suggestion......
My tool download link ...
Upload-V4.xlsm


Found one code but how to use in my userform ...
Code ping test.txt
 
Upvote 0
well, you have the function ready in the code ping test.txt you have found:
VBA Code:
Function Ping(strip)
    Dim objshell, boolcode
    Set objshell = CreateObject("Wscript.Shell")
    boolcode = objshell.Run("ping -n 1 -w 1000 " & strip, 0, True)
    If boolcode = 0 Then
        Ping = True
    Else
        Ping = False
    End If
End Function
The function will return true if the ping has returned, or FALSE if request has been timed out.
So you can make a quick check if the server reachable and then decide what to do next if it isn't, e.g.:
VBA Code:
If Not ping("server address here") then Exit Sub
Whether the telnet port is opened is another question.
 
Upvote 0
I don't know your network infrastructure so I can't really tell you how you can do it or why you cannot ping it directly. Or can't you really?
 
Upvote 0
Really thanks for your help , i will try but really i have very basic knowledge of VBA.
 
Upvote 0
Your last question is beyond VBA. It is a completely different subject.
Using this PING function you can ping anything you can access, but if it is in a different network and you need a tunnel to get there ...
If you don't know anything about this VBA will not solve it for you.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,127
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top