Jump to content
JiBe

UDF SSH

Recommended Posts

JiBe

  Hi to all,

 

 

I only am accustomed pas has posted on the forum (coz, I'm french). But I use it a lot.

So first of all, thank you all to participate in the evolution of this wonderful product.

Today is not one day like any other, I myself am decide has posted a UDF that I myself create and developed (there may be some bug) for some months.

So here it is:

This UDF allows to use the SSH protocol very easily in your code.

It uses the syntax as the TCPxxx() function.

Your code will be easier to convert :-).

 

excused my English, I'm French.

 

Example:

 

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.4.0
Author: Joseph Barone 2010-2015

Script Function:
Modele pour l'utilisation de la fonction ssh (plink).

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include
#include
#include
#include
#include
#include "SSH_udf.au3"

_SSHStartup()

Global $butt[6]

$Gui = GUICreate("SSH Console",550,400)
$label1 = GUICtrlCreateLabel("Adresse IP:",10,10,150,20) ; ip
$input1 = GUICtrlCreateInput("",10,25,150,20) ; ip
$label2 = GUICtrlCreateLabel("Tcp port:",170,10,150,20) ; port
$input2 = GUICtrlCreateInput("",170,25,60,20) ; port
$label6 = GUICtrlCreateLabel("Protocol:",240,10,40,20) ; port
$input6 = GUICtrlCreateInput("ssh",240,25,60,20) ; port
$butt[0] = GUICtrlCreateButton("Connect0",310,5,80,20,$BS_DEFPUSHBUTTON)
$butt[1] = GUICtrlCreateButton("Connect1",390,5,80,20)
$butt[2] = GUICtrlCreateButton("Connect2",470,5,80,20)
$butt[3] = GUICtrlCreateButton("Connect3",310,25,80,20)
$butt[4] = GUICtrlCreateButton("Connect4",390,25,80,20)
$butt[5] = GUICtrlCreateButton("Connect5",470,25,80,20)

$Checkbox = GUICtrlCreateCheckbox("RSA, Fingerprint, Alert AutoValidate", 330, 45, 205, 25)

$label4 = GUICtrlCreateLabel("Login:",10,45,150,20) ; login
$input4 = GUICtrlCreateInput("",10,60,150,20) ; login
$label5 = GUICtrlCreateLabel("Mot de passe:",170,45,150,20) ; password
$input5 = GUICtrlCreateInput("",170,60,150,20,$ES_PASSWORD) ; password

$label3 = GUICtrlCreateLabel("Commande a envoyer:",10,85,150,20) ; send command
$input3 = GUICtrlCreateInput("",10,100,310,20) ; send commande vers l'hote
$butt2 = GUICtrlCreateButton("Send",330,100,80,20,$BS_DEFPUSHBUTTON)
GUICtrlSetState($butt2,$GUI_DISABLE)

$edit = GUICtrlCreateEdit("",10,130,530,260,$WS_VSCROLL);,$WS_DISABLED))

GUISetState()


Global $ConnectedSocket[6] = [-1,-1,-1,-1,-1,-1]
Global $msg, $recv, $ret

; GUI Message Loop
;==============================================
While 1
$nmsg = GUIGetMsg()

If $nmsg = $GUI_EVENT_CLOSE Then ExitLoop

;;; connect part:
$b = 0
While 1
If $nMsg = $butt[$b] Then
If GUICtrlRead($butt[$b]) = "Connect"&$b Then
_SSHParametreSet("yesall",GUICtrlRead($Checkbox))
_SSHParametreSet("protocol",GUICtrlRead($input6))
_SSHParametreSet("login",GUICtrlRead($input4))
_SSHParametreSet("passwd",GUICtrlRead($input5))
$ConnectedSocket[$b] = _SSHConnect(GUICtrlRead($input1),GUICtrlRead($input2))
If $ConnectedSocket[$b] = 0 Then
MsgBox(0,"Erreur", "Impossible de ce connecter!!")
Else
GUICtrlSetData($butt[$b],"Close"&$b
GUICtrlSetState($butt2,$GUI_ENABLE)
EndIf
DisplayArray($_config)
ConsoleWrite("nb config:"&$_nbconf&@CRLF)
Else
_SSHCloseSocket($ConnectedSocket[$b])
GUICtrlSetData($butt[$b],"Connect"&$b
GUICtrlSetState($butt2,$GUI_DISABLE)
DisplayArray($_config)
ConsoleWrite("nb config:"&$_nbconf&@CRLF)
EndIf
EndIf

;;; send part:
If $nMsg = $butt2 Then
$ret = _SSHSend( $ConnectedSocket[$b] , GUICtrlRead($input3)&@crlf)
GUICtrlSetData($input3,"")
GUICtrlSetState($input3,$GUI_FOCUS)
EndIf


;;; receive part:
$recv = _SSHRecv( $ConnectedSocket[$b])
If $recv <> "" Then
GUICtrlSetData($edit, GUICtrlRead($edit) & $recv )
EndIf
GUICtrlSendMsg($edit, $EM_SCROLL, $SB_PAGEDOWN, 0)
$b += 1
If $b = UBound($butt) Then ExitLoop
WEnd

WEnd

_SSHCloseSocket($ConnectedSocket)
_SSHShutdown()

Exit

Func DisplayArray($array)
$i = 0
$j = 0
if UBound($array,1) = 0 Then Return
While 1
ConsoleWrite("(["&UBound($array,1)&"]["&UBound($array,2)&"]) ")
While 1
ConsoleWrite("["&$j&"]"&$array[$i][$j]&" ")
$j += 1
if UBound($array,2)<=$j Then ExitLoop
WEnd
ConsoleWrite(@CRLF)
$i += 1
$j = 0
if UBound($array,1)<=$i Then ExitLoop
WEnd
EndFunc

  

I join with UDF version of modified putty myself.  :-) LoL

but, it is not used with the UDF, it is included in the UDF.

 

putty-04012015- 92453+lic.zip

ssh_udf.zip

Edited by jeanphile
Added code tags
  • Like 1

Share this post


Link to post
Share on other sites
mLipok

Thanks for sharing.

mLipok


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-03-17

Share this post


Link to post
Share on other sites
czyt

Thanks for sharing~`


董小姐,你微笑的时候很美,就像安河桥下,清澈的水...

Share this post


Link to post
Share on other sites
lbsl

A nice share, the only question i have:Is there a way to turn off the automatic password responder after logging on?
I have to fill in a secondary password to enable advanced level and this password is not the same as the logon-password.

 

Share this post


Link to post
Share on other sites
MimiOne

Dear fellow citizen.
There are at least a bug:  

Impossible de ce connecté!!     >>> Impossible de se connecter !!
Commande a envoyé:   >> Commande à envoyer

Ce sera déjà plus "propre" ;)

Kind regards

  • Like 1

Share this post


Link to post
Share on other sites
JiBe

A nice share, the only question i have:Is there a way to turn off the automatic password responder after logging on?
I have to fill in a secondary password to enable advanced level and this password is not the same as the logon-password.

 

Yes, simply do not fill in the login and password.

Share this post


Link to post
Share on other sites
lbsl

Yes, simply do not fill in the login and password.

I did that, however that unfortunately does not work. After filling in the login data manually, the password will be reused whenever the phrase "Password:" comes back in the buffer. Hence the question how do i toggle off the auto responder completely so that nothing is triggered for that phrase.

login as: Using keyboard-interactive authentication.
Password: 

Router line 2 

Router>enable
Password: 
% Access denied

Router>

 

Share this post


Link to post
Share on other sites
JiBe
Hi lbsl;
 
Your problem is the operation of plink.
_SSHParametreSet ("login", GUICtrlRead ($input4))
_SSHParametreSet ("passwd", GUICtrlRead ($input5))
When you fills both of these parameters, plink will parsed messages login and password and answer. It cannot be the prevented.

 

to avoid the problem, should you send from the code the login and the password.

 

viewing I modified the example so that plink manages more authentication.
 
excuse my English, I'm French!

ssh2.au3

Share this post


Link to post
Share on other sites
lewisg

Do you think using this UDF and a POP3 UDF (or IMAP) I'd be able to retrieve GMail messages? 

Share this post


Link to post
Share on other sites
JiBe
Hi lewisg,
 
No, the ssl encryption is not implemented in the same way.

Messaging, to do with stunnel (also not too difficult to manage with Autoit)

sorry.

Share this post


Link to post
Share on other sites
Chamlien

very nice. if this udf can turn on ssh tunnel, i will be very powerful.

Share this post


Link to post
Share on other sites
JiBe

Hi Chamlien,

It can, but it's a little more difficult to set up :-)

 

Single Port Redirerction

$__PortForwardings = "L8080=192.168.0.200:80"

 
Dynamic port forwarding (used for example with Proxifier)

$__PortForwardings = "D3128="

Edited by JiBe

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • ScriptJunky
      By ScriptJunky
      I noticed a lack of a constants file for _WinAPI_GetSystemMetrics() so I made this for anyone who wants to add it to their library. Enjoy!  (file attached below)
      #include-once ; #INDEX# ======================================================================================================================= ; Title .........: WinAPI GetSystemMetrics Constants ; AutoIt Version : 3.3.14.5 ; Language ......: English ; Description ...: Constants for _WinAPI_GetSystemMetrics(). ; Author(s) .....: ScriptJunky ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== ; _WinAPI_GetSystemMetrics() Global Const $ARRANGE = 56 Global Const $CLEANBOOT = 67 Global Const $CMONITORS = 80 Global Const $CMOUSEBUTTONS = 43 Global Const $CONVERTIBLESLATEMODE = 0x2003 Global Const $CXBORDER = 5 Global Const $CXCURSOR = 13 Global Const $CXDLGFRAME = 7 Global Const $CXDOUBLECLK = 36 Global Const $CXDRAG = 68 Global Const $CXEDGE = 45 Global Const $CXFIXEDFRAME = 7 Global Const $CXFOCUSBORDER = 83 Global Const $CXFRAME = 32 Global Const $CXFULLSCREEN = 16 Global Const $CXHSCROLL = 21 Global Const $CXHTHUMB = 10 Global Const $CXICON = 11 Global Const $CXICONSPACING = 38 Global Const $CXMAXIMIZED = 61 Global Const $CXMAXTRACK = 59 Global Const $CXMENUCHECK = 71 Global Const $CXMENUSIZE = 54 Global Const $CXMIN = 28 Global Const $CXMINIMIZED = 57 Global Const $CXMINSPACING = 47 Global Const $CXMINTRACK = 34 Global Const $CXPADDEDBORDER = 92 Global Const $CXSCREEN = 0 Global Const $CXSIZE = 30 Global Const $CXSIZEFRAME = 32 Global Const $CXSMICON = 49 Global Const $CXSMSIZE = 52 Global Const $CXVIRTUALSCREEN = 78 Global Const $CXVSCROLL = 2 Global Const $CYBORDER = 6 Global Const $CYCAPTION = 4 Global Const $CYCURSOR = 14 Global Const $CYDLGFRAME = 8 Global Const $CYDOUBLECLK = 37 Global Const $CYDRAG = 69 Global Const $CYEDGE = 46 Global Const $CYFIXEDFRAME = 8 Global Const $CYFOCUSBORDER = 84 Global Const $CYFRAME = 33 Global Const $CYFULLSCREEN = 17 Global Const $CYHSCROLL = 3 Global Const $CYICON = 12 Global Const $CYICONSPACING = 39 Global Const $CYKANJIWINDOW = 18 Global Const $CYMAXIMIZED = 62 Global Const $CYMAXTRACK = 60 Global Const $CYMENU = 15 Global Const $CYMENUCHECK = 72 Global Const $CYMENUSIZE = 55 Global Const $CYMIN = 29 Global Const $CYMINIMIZED = 58 Global Const $CYMINSPACING = 48 Global Const $CYMINTRACK = 35 Global Const $CYSCREEN = 1 Global Const $CYSIZE = 31 Global Const $CYSIZEFRAME = 33 Global Const $CYSMCAPTION = 51 Global Const $CYSMICON = 50 Global Const $CYSMSIZE = 53 Global Const $CYVIRTUALSCREEN = 79 Global Const $CYVSCROLL = 20 Global Const $CYVTHUMB = 9 Global Const $DBCSENABLED = 42 Global Const $DEBUG = 22 Global Const $DIGITIZER = 94 Global Const $IMMENABLED = 82 Global Const $MAXIMUMTOUCHES = 95 Global Const $MEDIACENTER = 87 Global Const $MENUDROPALIGNMENT = 40 Global Const $MIDEASTENABLED = 74 Global Const $MOUSEPRESENT = 19 Global Const $MOUSEHORIZONTALWHEELPRESENT = 91 Global Const $MOUSEWHEELPRESENT = 75 Global Const $NETWORK = 63 Global Const $PENWINDOWS = 41 Global Const $REMOTECONTROL = 0x2001 Global Const $REMOTESESSION = 0x1000 Global Const $SAMEDISPLAYFORMAT = 81 Global Const $SECURE = 44 Global Const $SERVERR = 289 Global Const $SHOWSOUNDS = 70 Global Const $SHUTTINGDOWN = 0x2000 Global Const $SLOWMACHINE = 73 Global Const $STARTER = 88 Global Const $SWAPBUTTON = 23 Global Const $TABLETPC = 86 Global Const $XVIRTUALSCREEN = 76 Global Const $YVIRTUALSCREEN = 77  
      WinAPISystemMetricsConstants.au3
    • rcmaehl
      By rcmaehl
      A UDF with Extended Functions for Window Management
       
      Notes:
      Fixes WinGetClassList's barbaric returning of a @LF separated string instead of an array.
       
      Potential Uses:
      Automating applications that change their controls' handles/classes on each launch (e.g. half of Cisco's programs)
       
      Functions:
      _WinGetClassList
      _WinGetClassNNList
      _WindowGetHandleList
      _WindowGetHandleListFromPos
       
      Download: 
      WindowEx.zip  (v0.4)
       
      Changelog:
      10/04/2016 (v0.4): _WinGetClassNNList Fixed : Not Returning an Index when using $2D_ARRAY _WinGetClassNNList Fixed : Not Properly returning $aArray[x][1] on Classes with instances > 9 when using $2D_ARRAY 10/03/2016 (v0.3): _WinGetClassList Added : Exactly the same as WinGetClassList but returns a more civilized Array _WinGetClassNNList Added : Returns Classes and their instances in either a 1D or 2D array depending on Flags _WindowGetHandleList Renamed: _WinGetHandleList SCRIPT BREAKING! _WindowGetHandleListFromPos Renamed: _WinGetHandleListFromPos SCRIPT BREAKING! 10/01/2016 (v0.2): WindowsExConstants.au3 Added : Flags in _WindowGetHandleListFromPos _WindowGetHandleListFromPos Removed: ConsoleWrite left in during debug _WindowGetHandleListFromPos Added : Flag for if part of a Control is at $X, $Y return it as well. 10/01/2016 (v0.1): _WindowGetHandleList Added : Retrieves the handles of classes from a window. _WindowGetHandleListFromPos Added : Retrieves the handles of classes at a specific position from a window. Known and Reported Bugs:
      None reported To Do:
      To Be Decided. Opinions welcome! Upcoming Changes:
      To Be Decided.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone

      I was playing a little bit with "Screen Capture" UDF, and I was trying to make a "Window" capture, but, since I made a GUI which through I fire the event "Capture", my GUI is captured as well, and I don't want to
      This is the line of code that makes the capture:
       
      _ScreenCapture_CaptureWnd($strScreenCaptureFileName, $objActiveWindow, 0, 0, -1, -1, False) And these are the lines of code which select the "active" window:
       
      Local $objCurrentWindow = 9999 If _IsPressed("01") Then $objCurrentWindow = WinGetHandle("[ACTIVE]") If $objCurrentWindow <> $objMyGUI Then $objActiveWindow = $objCurrentWindow EndIf EndIf Sorry If I made stupid mistakes
      Thanks in advance.

      Francesco
    • kcvinu
      By kcvinu
      Hi all,
      I am playing with _GUICtrlButton_Create function. How can i change this button's (or the entire form's) font ?. The in-built GUICtrlSetFont function is not working even when i convert the control handle to control ID with _WinAPI_GetDlgCtrlID ( ) function.  Do i need to use CreateFont api finction and send WM_SETFONT message ? Or is there any other easy and safe ways to do this ?. Thanks in advance.
      Note : This window is created by CreateWindowEx function, not by GUICreate function. 
    • okolaris
      By okolaris
      Hey everyone,
      I thought I might share my little Language UDF plus the more powerful SciTE Tool to ship Strings from SciTE into the xml file. While I haven't had the time to fully adapt the small UDF to one of the big XML-UDFs the so called "Language Transmitter" that basically writes the XML file for you runs mostly on "XML DOM wrapper (COM)" by eltorro. The Transmitter should work with other XML-Language-UDFs depending on their encoding.
       
      First let's start with the UDF, there are two functions of interest: _LangInit($sFilePath) and s($sString) As you will have guessed, _LangInit($sFilePath) is called once to initialize the UDF and s($sString) is used to receive the string to your key. Plain and simple.
      Now to the actual "new" part, the Language Transmitter. It basically allows you to transfer a selected String from SciTE into a xml file. While doing so it will scan for AutoIt variables, macros etc. and parse the string to fit StringFormat(). It then saves the formatted string in the xml file and returns the formatted call into SciTE. If the selected string is already defined it will directly parse the key into SciTE. To change the default output file, you can either edit the ini-file in the @ScriptDir of the LanguageTransmitter.exe or press Alt+A on empty space again and keep clicking cancel/no until the Transmitter let's you select the current output file. Standard output is strings.xml in the current opened AutoIt Script.
      Example:
      ; given the line: MsgBox(16, 'Error', 'Error message') ; select 'Error' run the Transmitter follow the instructions, repeat with 'Error message'. Outcome (e.g.): MsgBox(16, s('Error'), s('Error_msg')) ; Variables and Macro example: $sString = "Value: " & $iValue & @CRLF & 'Another value: '& $iValue2 ; Select the full string including all AutoIt variables and macros etc. in SciTE and press Alt+A (default) to run the LanguageTransmitter ; follow the instructions and it will then paste a formatted string like that into SciTE: $sVar = StringFormat(s('Key'), $iValue, $iValue2) ; the correlating xml entry should look like that: ; <string name="Key">Value: %s\r\nAnother value: %s</string> ; as you can see @CRLF has been replaced with \r\n as well. If you are working on a project and want to directly add a string to the xml file just start the Language Transmitter without selecting any text, enter your string and a key.
      SetUp/Installation
      Examples
      Since xml files are required all examples can be found in the zip file. There are two examples, one includes a language selection interface.
      Language File Checker
      I added a script to check whether the xml file contains all required strings or even unnecessary strings.
       
      Hope you like my little helper!
       
      UDF - LanguageSupport.zip
×