jackylee0908 Posted December 30, 2024 Posted December 30, 2024 (edited) Hi sir, I have a GUI called launcher.exe and there is a column to request user to input IP address: $v5 = GUICtrlRead($PDUIP) If GUICtrlRead($CheckBox) = $GUI_UNCHECKED Then Run("execute.exe " & "11" & " " & $v1 & " " & $v2 & " " & $v3 & " " & $v4 & " " & $v7 & " " & $v8 & " " & $v9 & " " & $v5 & " " & $v6 & " " & $v12 & " " & $v13) ExitLoop Else Run("execute.exe " & "12" & " " & $v1 & " " & $v2 & " " & $v3 & " " & $v14 & " " & $v7 & " " & $v8 & " " & $v9 & " " & $v5 & " " & $v6 & " " & $v12 & " " & $v13) ExitLoop EndIf The $v5 with IP address will be sent to another executable 'execute.exe', and it will be used for below code: _APC("off", $CmdLine[9], $CmdLine[10], $CmdLine[11], $CmdLine[12]) Func _APC($v100, $v101, $v102, $v103, $v104) ; v100=on or off, v101=PDUIP, v102=PDUPort, v103=PDUAC, v104=PDUPW TcpStartUp () $remoteserver = tcpconnect($v101, "23") ;client 2 TELNETserver, leave "TCPNameToIP" out if you have IP only. 23 is telnetport. If $remoteserver = -1 Then msgbox(16,"error","Cannot connect to telnet server.") While 1 sleep ('100'); $Recv1 = TCPRecv($remoteserver, "1000");1000 means max stringlen. ConsoleWrite($recv1);what the server replies If stringinstr($recv1, "User Name :") > 0 Then tcpsend($remoteserver, $v103 & @crlf) ElseIf stringinstr($recv1, "Password :") > 0 Then tcpsend($remoteserver, $v104 & @crlf) ElseIf stringinstr($recv1, "apc>") > 0 Then If $v100 = "off" Then tcpsend($remoteserver, "olOff " & $v102 & @crlf) sleep ('100') ElseIf $v100 = "on" Then tcpsend($remoteserver, "olOn " & $v102 & @crlf) sleep ('100') EndIf tcpsend($remoteserver, "quit" & @crlf) TCPShutdown() ExitLoop EndIf Wend EndFunc It doesn't work for me(pop out an error msgbox 'Cannot connect to telnet server.'), and I guess that it is because the transition of variable from $v5 -> $CmdLine[9] -> $v101 are without quote, because it needs quote for below command: $remoteserver = tcpconnect($v101, "23") For example: $remoteserver = tcpconnect("192.168.1.1", "23") But the IP might be with no quote: $remoteserver = tcpconnect(192.168.1.1, "23") That might be the reason that the telnet can't run. Please advise how to add quote into variable, thanks. Edited December 30, 2024 by jackylee0908
jackylee0908 Posted December 30, 2024 Author Posted December 30, 2024 Tried to add quote in input field so that the $v5 could be "192.168.1.1", but when the launcher.exe transfer the $v5 to execute.exe with $CmdLine[9], it would become without quote: 192.168.1.1...... $v5 = GUICtrlRead($PDUIP) That means, I need to quote it in execute.exe on $CmdLine[9] and store to a variable, how to do that?
ioa747 Posted December 30, 2024 Posted December 30, 2024 (edited) Maybe this will help. expandcollapse popup; https://www.autoitscript.com/forum/topic/212587-how-to-set-a-variable-with-a-quoted-ip-address-from-the-input-field/#findComment-1539893 #include <Array.au3> _CmdLineWatcher() ; 1 2 3 4 5 6 7 8 9 10 11 12 ;Run("execute.exe " & "11" & " " & $v1 & " " & $v2 & " " & $v3 & " " & $v4 & " " & $v7 & " " & $v8 & " " & $v9 & " " & $v5 & " " & $v6 & " " & $v12 & " " & $v13) Run('"' & @AutoItExe & '" "' & @ScriptFullPath & '" _APC_Caller ' & '"off" 2 3 4 5 6 7 8 "192.168.1.1" 23 "' & @UserName & '" "My p@ssWord!!"') ;--------------------------------------------------------------------------------------- Func _APC_Caller($p1, $p2, $p3, $p4, $p5, $p6, $p7, $p8, $p9, $p10, $p11, $p12) ConsoleWrite("@NumParams=" & @NumParams & @CRLF) Local $sVal1 = "", $sVal2 = "" ;~ For $i = 1 To @NumParams ;~ $sVal1 &= "$p" & $i & "=" & Eval("p" & $i) & @CRLF ;~ Next $sVal2 = "_APC( " & $p1 & ", " & $p9 & ", " & $p10 & ", " & $p11 & ", " & $p12 & " )" MsgBox($MB_SYSTEMMODAL, "", "@NumParams = " & @NumParams & @CRLF & @CRLF & $sVal1 & @CRLF & $sVal2) $p10 = Int($p10) ; *** and which parameter you need to convert to the appropriate type format ??? ;~ _APC($p1, $p9, $p10, $p11, $p12) ; _APC("off", $CmdLine[9], $CmdLine[10], $CmdLine[11], $CmdLine[12]) EndFunc ;==>_APC_Caller ;--------------------------------------------------------------------------------------- Func _CmdLineWatcher() ; Run('"' & @AutoItExe & '" "' & @ScriptFullPath & '" FoldersGUI ' & $hWnd & ' 1') Local $aArgs = $CmdLine Local $sFunc If $aArgs[0] > 0 Then $sFunc = $aArgs[1] _ArrayDelete($aArgs, 1) $aArgs[0] = "CallArgArray" Call($sFunc, $aArgs) If @error = 0xDEAD And @extended = 0xBEEF Then ToolTip("error !! Function does not exist" & @CRLF & "or wrong number of parameter", Default, Default, @ScriptName, 3) Sleep(4000) ToolTip("") EndIf Exit EndIf EndFunc ;==>_CmdLineWatcher ;---------------------------------------------------------------------------------------- Edited December 30, 2024 by ioa747 added int() I know that I know nothing
argumentum Posted December 30, 2024 Posted December 30, 2024 (edited) 9 hours ago, jackylee0908 said: $v5 = GUICtrlRead($PDUIP) If GUICtrlRead($CheckBox) = $GUI_UNCHECKED Then Run("execute.exe " & "11" & " " & $v1 & " " & $v2 & " " & $v3 & " " & $v4 & " " & $v7 & " " & $v8 & " " & $v9 & " " & $v5 & " " & $v6 & " " & $v12 & " " & $v13) ExitLoop Else Run("execute.exe " & "12" & " " & $v1 & " " & $v2 & " " & $v3 & " " & $v14 & " " & $v7 & " " & $v8 & " " & $v9 & " " & $v5 & " " & $v6 & " " & $v12 & " " & $v13) ExitLoop EndIf $v5 = GUICtrlRead($PDUIP) If GUICtrlRead($CheckBox) = $GUI_UNCHECKED Then Run("execute.exe " & "11" & '" "' & $v1 & '" "' & $v2 & '" "' & $v3 & '" "' & $v4 & '" "' & $v7 & '" "' & $v8 & '" "' & $v9 & '" "' & $v5 & '" "' & $v6 & '" "' & $v12 & '" "' & $v13 & '"') ExitLoop Else Run("execute.exe " & "12" & '" "' & $v1 & '" "' & $v2 & '" "' & $v3 & '" "' & $v4 & '" "' & $v7 & '" "' & $v8 & '" "' & $v9 & '" "' & $v5 & '" "' & $v6 & '" "' & $v12 & '" "' & $v13 & '"') ExitLoop EndIf 9 hours ago, jackylee0908 said: For example: $remoteserver = tcpconnect("192.168.1.1", "23") the example shows: ; Assign Local variables the loopback IP Address and the Port. Local $sIPAddress = "127.0.0.1" ; This IP Address only works for testing on your own computer. Local $iPort = 65432 ; Port used for the connection. ; Assign a Local variable the socket and connect to a Listening socket with the IP Address and Port specified. Local $iSocket = TCPConnect($sIPAddress, $iPort) Hence the IP is a string and the port is an integer. Therefore, you are to code it like tcpconnect("192.168.1.1", 23) because the 1st is a str. and the 2nd is an int. ..go Rey.. ( I like music ) Edited December 30, 2024 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted December 30, 2024 Posted December 30, 2024 8 hours ago, jackylee0908 said: Tried to add quote in input field so that the $v5 could be "192.168.1.1", but... If you need a type from something like a command line, then you'd have to do that yourself, like $remoteserver = tcpconnect(String("192.168.1.1"), Int("23")) $remoteserver = TCPConnect(String($v101), 23) ioa747 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
ioa747 Posted December 30, 2024 Posted December 30, 2024 TCPConnect ( IPAddr, port ) I think it's more likely that the problem is in the parameter port because the parameters come from $CmdLine and they are converted to text therefore, it needs to be converted to an integer during the call TCPConnect($CmdLine[9], int($CmdLine[10]) ) argumentum 1 I know that I know nothing
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now