Jump to content

Am I able to get and recieve Packet Loss via AutoIT or from running commands from AutoIT in CMD?


Recommended Posts

Hi there!

I am working on a tool that displays ping so far. The next update that I want to add is Packet loss but I'm not sure if there is a function or a script that displays Packet Loss, or would I have to run a command from an AutoIT script via Powershell, CMD etc.

Is there any threads or posts that say anything about displaying Packet Loss?

Thanks for your help in advance!

Kind Regards,

Supra

Link to comment
Share on other sites

Use Plink in combination with Autoit below is a UDF I use for things like this:

 

;~ Global $sPassword = "password"

;~ Global $iPIDPlink = _PlinkConnect("10.1.0.1", "admin", "admin")
;~ If @error Then Exit 1

;~ _PlinkSend($iPIDPlink, "enable" & @CR)
;~ Global $sPlinkReturn = _PlinkRead($iPIDPlink)
;~ If StringInStr($sPlinkReturn, "Password") Then ;Expected password prompt text.
;~ _PlinkSend($iPIDPlink, $sPassword & @CR)
;~ $sPlinkReturn = _PlinkRead($iPIDPlink) ;Get return text from entering the password.
;~ If StringInstr($sPlinkReturn, "Access denied") Or StringInstr($sPlinkReturn, "FATAL") Then
;~ Exit 3
;~ _PlinkExit($iPIDPlink)
;~ EndIf
;~ _PlinkSend($iPIDPlink, "reload" & @CR)
;~ $sPlinkReturn = _PlinkRead($iPIDPlink)
;~ EndIf
;~ _PlinkExit($iPIDPlink)

; #FUNCTION# ====================================================================================================================
; Name ..........: _PlinkConnect
; Description ...: Use Plink to connect to a remote server using SSH.
; Syntax ........: _PlinkConnect($sHostName, $sUserName, $sPassword)
; Parameters ....: $sHostName - A string of the host server name or IP Address.
;                 $sUserName - A string of the SSH User Name.
;                 $sPassword - A string of the SSH Password.
; Return values .: Success - $iPID - the PID of the Plink session.
;                 Failure - 0, sets @error to:
;                 |1 - Plink.exe not found in @ScriptDir.
;                 |2 - Error running Plink.exe.
; Author ........: spudw2k
; Modified ......: Adam Lawrence (AdamUL)
; Remarks .......:
; Related .......: _PlinkExit
; Link ..........: http://www.autoitscript.com/forum/topic/...uter-via-ssh/page__p__910252#e
; Example .......: No
; ===============================================================================================================================
Func _PlinkConnect($sHostName, $sUserName, $sPassword, $sEXE = @ScriptDir & "plink.exe")
    If Not FileExists($sEXE) Then Return SetError(1, 0, 0)
$iPID = Run('"' & $sEXE & '" -ssh -pw ' & $sPassword & " " & $sUserName & "@" & $sHostName, @ScriptDir, @SW_HIDE, 0x1 + 0x8)  ;Run SSH.EXE
    If Not $iPID Then Return SetError(2, 0, 0)
    $iPIDCurrent = $iPID
    $sReturn = _PlinkRead($iPID)  ;Check for Login Success - Prompt
    If StringInstr($sReturn, "Store key in cache? (y/n)") Then
        _PlinkSend($iPID, "y" & @CR)
        $sReturn = _PlinkRead($iPID)
    EndIf
    If StringInstr($sReturn, "Access denied") Or StringInstr($sReturn, "FATAL") Or StringInStr($sReturn, "does not exist") or StringInStr($sReturn, "password:") Then Return SetError(3, 0, 0)
    Return $iPID
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _PlinkRead
; Description ...: Read text data returned from the connected server.
; Syntax ........: _PlinkRead($iPID)
; Parameters ....: $iPID - PID returned from _PlinkConnect.
; Return values .: Success - String returned from StdOutRead of Plink.
;                 Failure - -1, sets @error to:
;                 |1 - Invaild Plink PID.
; Author ........: spudw2k
; Modified ......: Adam Lawrence (AdamUL)
; Remarks .......:
; Related .......: _PlinkSend
; Link ..........: http://www.autoitscript.com/forum/topic/...uter-via-ssh/page__p__910252#e
; Example .......: No
; ===============================================================================================================================
Func _PlinkRead($iPID)
    If Not $iPID Then Return SetError(1, 0, -1)
    Local $sDataA
    Local $sDataB
    $zed = 0
    Do
        $sDataB = $sDataA
        Sleep(100)
        $sDataA &= StdOutRead($iPID)
        If @error Then ExitLoop
        $zed += 1

        If $zed > 50 Then ExitLoop
    Until $sDataB = $sDataA And $sDataA And $sDataB
    Return $sDataA
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _PlinkSend
; Description ...: Send text data to the connected server.
; Syntax ........: _PlinkSend($iPID, $sCmd)
; Parameters ....: $iPID - PID returned from _PlinkConnect.
;                 $sCmd - A string of the command to send.
; Return values .: Success - 1
;                 Failure - 0, sets @error to:
;                 |StdinWrite @error code.
; Author ........: spudw2k
; Modified ......: Adam Lawrence (AdamUL)
; Remarks .......:
; Related .......: _PlinkRead
; Link ..........: http://www.autoitscript.com/forum/topic/...uter-via-ssh/page__p__910252#e
; Example .......: No
; ===============================================================================================================================
Func _PlinkSend($iPID, $sCmd)
    $iChars = StdinWrite($iPID,$sCmd)
Return SetError(@error, 0, $iChars)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _PlinkExit
; Description ...: End a Plink session.
; Syntax ........: _PlinkExit($iPID)
; Parameters ....: $iPID - PID returned from _PlinkConnect.
; Return values .: Success - 1
;                 Failure - 0, sets @error to:
;                 |ProcessClose @error code.
; Author ........: spudw2k
; Modified ......: Adam Lawrence (AdamUL)
; Remarks .......:
; Related .......: _PlinkConnect
; Link ..........: http://www.autoitscript.com/forum/topic/...uter-via-ssh/page__p__910252#e
; Example .......: No
; ===============================================================================================================================
Func _PlinkExit($iPID)
    $iClosed = ProcessClose($iPID)
Return SetError(@error, 0, $iClosed)
EndFunc

 

Link to comment
Share on other sites

1 hour ago, rm4453 said:

Use Plink in combination with Autoit below is a UDF I use for things like this:

 

;~ Global $sPassword = "password"

;~ Global $iPIDPlink = _PlinkConnect("10.1.0.1", "admin", "admin")
;~ If @error Then Exit 1

;~ _PlinkSend($iPIDPlink, "enable" & @CR)
;~ Global $sPlinkReturn = _PlinkRead($iPIDPlink)
;~ If StringInStr($sPlinkReturn, "Password") Then ;Expected password prompt text.
;~ _PlinkSend($iPIDPlink, $sPassword & @CR)
;~ $sPlinkReturn = _PlinkRead($iPIDPlink) ;Get return text from entering the password.
;~ If StringInstr($sPlinkReturn, "Access denied") Or StringInstr($sPlinkReturn, "FATAL") Then
;~ Exit 3
;~ _PlinkExit($iPIDPlink)
;~ EndIf
;~ _PlinkSend($iPIDPlink, "reload" & @CR)
;~ $sPlinkReturn = _PlinkRead($iPIDPlink)
;~ EndIf
;~ _PlinkExit($iPIDPlink)

; #FUNCTION# ====================================================================================================================
; Name ..........: _PlinkConnect
; Description ...: Use Plink to connect to a remote server using SSH.
; Syntax ........: _PlinkConnect($sHostName, $sUserName, $sPassword)
; Parameters ....: $sHostName - A string of the host server name or IP Address.
;                 $sUserName - A string of the SSH User Name.
;                 $sPassword - A string of the SSH Password.
; Return values .: Success - $iPID - the PID of the Plink session.
;                 Failure - 0, sets @error to:
;                 |1 - Plink.exe not found in @ScriptDir.
;                 |2 - Error running Plink.exe.
; Author ........: spudw2k
; Modified ......: Adam Lawrence (AdamUL)
; Remarks .......:
; Related .......: _PlinkExit
; Link ..........: http://www.autoitscript.com/forum/topic/...uter-via-ssh/page__p__910252#e
; Example .......: No
; ===============================================================================================================================
Func _PlinkConnect($sHostName, $sUserName, $sPassword, $sEXE = @ScriptDir & "plink.exe")
    If Not FileExists($sEXE) Then Return SetError(1, 0, 0)
$iPID = Run('"' & $sEXE & '" -ssh -pw ' & $sPassword & " " & $sUserName & "@" & $sHostName, @ScriptDir, @SW_HIDE, 0x1 + 0x8)  ;Run SSH.EXE
    If Not $iPID Then Return SetError(2, 0, 0)
    $iPIDCurrent = $iPID
    $sReturn = _PlinkRead($iPID)  ;Check for Login Success - Prompt
    If StringInstr($sReturn, "Store key in cache? (y/n)") Then
        _PlinkSend($iPID, "y" & @CR)
        $sReturn = _PlinkRead($iPID)
    EndIf
    If StringInstr($sReturn, "Access denied") Or StringInstr($sReturn, "FATAL") Or StringInStr($sReturn, "does not exist") or StringInStr($sReturn, "password:") Then Return SetError(3, 0, 0)
    Return $iPID
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _PlinkRead
; Description ...: Read text data returned from the connected server.
; Syntax ........: _PlinkRead($iPID)
; Parameters ....: $iPID - PID returned from _PlinkConnect.
; Return values .: Success - String returned from StdOutRead of Plink.
;                 Failure - -1, sets @error to:
;                 |1 - Invaild Plink PID.
; Author ........: spudw2k
; Modified ......: Adam Lawrence (AdamUL)
; Remarks .......:
; Related .......: _PlinkSend
; Link ..........: http://www.autoitscript.com/forum/topic/...uter-via-ssh/page__p__910252#e
; Example .......: No
; ===============================================================================================================================
Func _PlinkRead($iPID)
    If Not $iPID Then Return SetError(1, 0, -1)
    Local $sDataA
    Local $sDataB
    $zed = 0
    Do
        $sDataB = $sDataA
        Sleep(100)
        $sDataA &= StdOutRead($iPID)
        If @error Then ExitLoop
        $zed += 1

        If $zed > 50 Then ExitLoop
    Until $sDataB = $sDataA And $sDataA And $sDataB
    Return $sDataA
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _PlinkSend
; Description ...: Send text data to the connected server.
; Syntax ........: _PlinkSend($iPID, $sCmd)
; Parameters ....: $iPID - PID returned from _PlinkConnect.
;                 $sCmd - A string of the command to send.
; Return values .: Success - 1
;                 Failure - 0, sets @error to:
;                 |StdinWrite @error code.
; Author ........: spudw2k
; Modified ......: Adam Lawrence (AdamUL)
; Remarks .......:
; Related .......: _PlinkRead
; Link ..........: http://www.autoitscript.com/forum/topic/...uter-via-ssh/page__p__910252#e
; Example .......: No
; ===============================================================================================================================
Func _PlinkSend($iPID, $sCmd)
    $iChars = StdinWrite($iPID,$sCmd)
Return SetError(@error, 0, $iChars)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _PlinkExit
; Description ...: End a Plink session.
; Syntax ........: _PlinkExit($iPID)
; Parameters ....: $iPID - PID returned from _PlinkConnect.
; Return values .: Success - 1
;                 Failure - 0, sets @error to:
;                 |ProcessClose @error code.
; Author ........: spudw2k
; Modified ......: Adam Lawrence (AdamUL)
; Remarks .......:
; Related .......: _PlinkConnect
; Link ..........: http://www.autoitscript.com/forum/topic/...uter-via-ssh/page__p__910252#e
; Example .......: No
; ===============================================================================================================================
Func _PlinkExit($iPID)
    $iClosed = ProcessClose($iPID)
Return SetError(@error, 0, $iClosed)
EndFunc

 

Hi,

Thanks for replying to me that fast.

I will need to read through all the functions and modify it so it suits my needs.

This might take a while because I'm new to this but bare with me for a while. 

Have a good day!

 

Kind Regards,

Supra

Link to comment
Share on other sites

On 3/20/2019 at 9:31 AM, rm4453 said:

Always glad to help good luck!

 

Thanks for wishing me luck, but I had a long look and attempted to edit my code to suit a connection to google.ie (AS an example).

Would you be able to fill it in for me (Sorry about this, I'm trying to learn as much as I can but struggling hard), and I would take a look at how it could suit me?

 

Kind Regards,

Supra

Link to comment
Share on other sites

7 hours ago, supraaxdd said:

Thanks for wishing me luck, but I had a long look and attempted to edit my code to suit a connection to google.ie (AS an example).

Would you be able to fill it in for me (Sorry about this, I'm trying to learn as much as I can but struggling hard), and I would take a look at how it could suit me?

 

Kind Regards,

Supra

Post the code you have attempted so far.

Link to comment
Share on other sites

3 hours ago, rm4453 said:

Post the code you have attempted so far.

The thing is that I have no idea what to put in the variables. If you need more info, i'll try to figure out what I need to do. 

Ps: Is this script an include? And can I use the functions in the same script so that I can test what happens?

 

Kind Regards,

Supra

Link to comment
Share on other sites

1 minute ago, supraaxdd said:

The thing is that I have no idea what to put in the variables. If you need more info, i'll try to figure out what I need to do. 

Ps: Is this script an include? And can I use the functions in the same script so that I can test what happens?

 

Kind Regards,

Supra

you can save it as a .au3 and use it as an include of course!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...