Jump to content

inputbox and an error


Nunos
 Share

Recommended Posts

So I wanted to use Guinness's tracert snippet tp prompt for a user to input what they wanted to tracert to but I am unable to even make it work as is below before I even try to sort how to get an inputbox in it. I am getting the following.

ERROR: $sOutput previously declared as a 'Const'.

$sOutput &= StdoutRead($iPID)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

#include 

ConsoleWrite(_Tracert("www.duckduckgo.com") & @CRLF)

Func _Tracert(Const $sURL)
; -d = Do Not Resolve Host & -h Is The Number Of Hops.
Local Const $sData = _RunStdOutRead('tracert -d -h 1 ' & $sURL, @SystemDir)

Local Const $aReturn = StringRegExp($sData, '\[([\d.]{7,15})\]', 3)

If @error Then
Return SetError(1, 0, -1)
EndIf

Return $aReturn[0]
EndFunc ;==>_Tracert

Func _RunStdOutRead($sCommand, $sWorkingDirectory = @SystemDir)
Local Const $iPID = Run(@ComSpec & ' /c ' & $sCommand, $sWorkingDirectory, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sOutput = ''

While 1
$sOutput &= StdoutRead($iPID)

If @error Then
ExitLoop
EndIf
WEnd

Return $sOutput
EndFunc ;==>_RunStdOutRead

If someone could advise me as to what I am doing wrong here I would appreciate the help. I also would like some direction on using an inputbox to get the user to type in a url or ip to tracert too. Firstly do I assign that to the $sURL above? Also is there a way to verify it is an IP address or a url?

Thank you in advance.

Link to comment
Share on other sites

Not sure what to assign it to and then how to send it to the msgbox instead of console. I am not great at scripting if you can't tell. I made the InputBox and assigned it to $trace then added that to the console write but I don't think this is right and I would really like to somehow get the output to say like a message box or similar. Thank you for your time and I appologize if I sound like a complete noob.

#include

Local $trace = InputBox("Tracert", "Please enter a url or IP address to test.", "www.bing.com")

ConsoleWrite(_Tracert($trace) & @CRLF)

Func _Tracert(Const $sURL)
; -d = Do Not Resolve Host & -h Is The Number Of Hops.
Local Const $sData = _RunStdOutRead('tracert -d -h 1 ' & $sURL, @SystemDir)

Local Const $aReturn = StringRegExp($sData, '[([d.]{7,15})]', 3)

If @error Then
Return SetError(1, 0, -1)
EndIf

Return $aReturn[0]
EndFunc ;==>_Tracert

Func _RunStdOutRead($sCommand, $sWorkingDirectory = @SystemDir)
Local $iPID = Run(@ComSpec & ' /c ' & $sCommand, $sWorkingDirectory, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sOutput = ''

While 1
$sOutput &= StdoutRead($iPID)

If @error Then
ExitLoop
EndIf
WEnd

Return $sOutput
EndFunc ;==>_RunStdOutRead
Edited by Nunos
Link to comment
Share on other sites

Thank You JMon. Works fine but it only returns one IP I was thinking it would return all of the hops. Not sure if I can get it to send all of the information back from the cmd window or not but no biggy if not. I appreciate your help. :D

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...