Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/29/2017 in all areas

  1. Hi! If you liked my TCPServer UDF, you'll also like this one. Following the same principles, this TCPClient UDF helps you on handling multiple connections to different servers, and set actions depending on two events: OnReceive and OnDisconnect. It is also multi server (you can connect to many servers at once) and you can also bind a Console-based executable to the socket (similar to -e parameter in NetCat). This feature is useful if you want to use some Console UDF to create a TCP application and don't want to deal with the TCP* functions. Also, it runs on background just firing events, it won't pause your script while waiting/receiving data, so you can do anything else (close and open connections, allow the user to click buttons or just wait on an infinite loop) that your callbacks will be called once the event is fired It is also very easy to use. See this examples: Example #1: Connecting to a basic server By running this (as soon as you open a basic server with Netcat) you will receive a message box telling you when the server closes the connection (the socket ID and his IP address are passed as parameter to your callback function) and also when the server sends something over the TCP socket (the data sent is passed as parameter). #cs Download netcat at https://eternallybored.org/misc/netcat/ Execute this script Run in CMD: nc -vv -l -p 8081 #ce #include "TCPClient.au3" ; First we set the callback functions for the two events (none of them is mandatory) _TCPClient_OnDisconnect("disconnect") _TCPClient_OnReceive("received") ; And a parameter _TCPClient_DebugMode(True) ; Finally we connect to the server at port 8081 at any interface _TCPClient_Connect('127.0.0.1', 8081) Func disconnect($iSocket, $sIP) MsgBox(0, "Server disconnected", "Server " & $sIP & " disconnected from socket " & $iSocket) EndFunc ;==>disconnect Func received($iSocket, $sIP, $sData, $sPar) MsgBox(0, "Data received from " & $sIP, $sData & @CRLF & "Parameter: " & $sPar) _TCPClient_Send($iSocket, "You wrote: " & $sData) _TCPClient_SetParam($iSocket, 'will write again') EndFunc ;==>received While 1 Sleep(100) WEndExample #2: Requesting a page from a HTTP server In this example, we run this code and it will get the response from a HTTP server. Of course, as we are requesting google.com index, it may just show a redirect page to a local (with country top-level domain) Google page or with some stuff on the URL. #include "TCPClient.au3" _TCPClient_OnReceive("received") _TCPClient_DebugMode(True) $iSocket = _TCPClient_Connect(TCPNameToIP('google.com'), 80) If @error Then Exit _TCPClient_Send($iSocket, "GET / HTTP/1.0" & @CRLF & @CRLF) Func received($iSocket, $sIP, $sData, $sParam) MsgBox(0, "Data received", $sData) _TCPClient_Disconnect($iSocket) EndFunc ;==>received While 1 Sleep(100) WEndExample #3: Command prompt bound to the socket after password requesting By running this example, we will be asked for a password, which is 123456 as we set on the script. If the password is correct, we will see the Command Prompt live-updated (try running a ping to some server, for example). #include "TCPClient.au3" #cs To test this example, execute a netcat server, running this commands: nc -vv -l -p 31337 #ce Global $Password = "123456" _TCPClient_OnReceive("receive") _TCPClient_OnDisconnect("disconnect") _TCPClient_DebugMode() Func receive($iSocket, $sIP, $sData, $mPar) If $mPar = "login" Then If $sData = $Password Then ; right password, let's change the parameter _TCPClient_SetParam($iSocket, "logged") ; and now bind _TCPClient_BindAppToSocket($iSocket, "cmd.exe") Else _TCPClient_Send($iSocket, "Wrong password. Try again: ") EndIf Else If $sData = "exit" Then ; unbinds _TCPClient_UnBindAppToSocket($iSocket) ; says bye _TCPClient_Send($iSocket, "See you") ; closes connection _TCPClient_Disconnect($iSocket) Else ; sends command directly to the process _TCPClient_SendToBound($iSocket, $sData) EndIf EndIf EndFunc Func disconnect($iSocket, $sIP) MsgBox(0, $iSocket, $sIP) EndFunc $iSocket = _TCPClient_Connect('127.0.0.1', '31337') If @error Then MsgBox(0, "", "could not connect. Error: " & @error) Exit EndIf ; Sets parameter to login, so we know what the server is doing _TCPClient_SetParam($iSocket, "login") _TCPClient_Send($iSocket, "Please enter password: ") While True Sleep(100) WEndThe limit is your imagination? Well, maybe. Functions list: _TCPClient_Connect($sSvr, $iPort) _TCPClient_Disconnect($iSocket) _TCPClient_SetParam($iSocket, $sPar) _TCPClient_Send($iSocket, $sData) _TCPClient_Broadcast($sData [, $iExceptSocket = 0 ]) _TCPClient_ListConnections() _TCPClient_BindAppToSocket($iSocket, $sCommand [, $sWorkingDir = @WorkingDir ]) _TCPClient_SendToBound($iSocket, $sData) _TCPClient_UnBindAppToSocket($iSocket) _TCPClient_OnReceive($sCallback) _TCPClient_OnDisconnect($sCallback) _TCPClient_DebugMode([ $bMOde = "toggle" ]) _TCPClient_AutoTrim([ $bMode = "toggle" ]) _TCPClient_SocketToConnID($iSocket) _TCPClient_ConnIDToSocket($iConn) _TCPClient_SocketToIP($iSocket)Help file and more examples included! Latest version: 1.0.0 Download: https://www.autoitscript.com/forum/files/file/377-tcpclient-udf/ Changelog 1.0.0 - First release - 03/12/2015If you can't open the help file, please uncompress it, go to properties and click Unlock. Fork me on Github: http://github.com/jesobreira/tcpclient-udf
    1 point
  2. freyaharts, That is not the solution I suggested - declaring variables as Global within a function is not good coding practice: #include <Misc.au3> HotKeySet("{esc}", "_Exit") Global $Color ; Declare the variable as Global here so it is seen by all functions <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $Coords = AskUser() Start() Func AskUser() MsgBox(0, "User Input", "Please click mouse your screen" & @CRLF & "Press OK, and then move your mouse there and click") Do Sleep(50) Until _IsPressed(01) $Coords = MouseGetPos() $Color = PixelGetColor($Coords[0], $Coords[1]) MsgBox(0, "info", "Your coords and color have been stored for later use") Return $Coords EndFunc ;==>AskUser Func Start() While 1 If PixelGetColor($Coords[0], $Coords[1]) = $Color Then Sleep(200) ;run whole script Else Sleep(100) EndIf WEnd EndFunc ;==>Start Func _Exit() Exit EndFunc ;==>_Exit M23
    1 point
  3. 0 freyaharts, That variable is declared as Local to the AskUser function and so is invisible to the Start function. The Variables - using Global, Local, Static and ByRef tutorial in the Wiki might be a useful read to help you understand more about scoping variables. M23
    1 point
  4. Why don't you compare using _DateDiff ? Local $File = FileGetTime(FilePatch) Local $sFileDate = $File[0] & "/" & $File[1] & "/" & $File[2] If _DateDiff("D", $sFileDate, _NowCalcDate()) > 3 Then MsgBox(0, '', 'Fail')
    1 point
  5. Hmmm should work. WIth the information provided i have no issues: #include <IE.au3> #include <Array.au3> $oIE = _IECreate() _IEBodyWriteHTML($oIE, StringRegExp(FileRead(@ScriptFullPath),"(?s)(<[h]tml>.*<\/html>)",1)[0]) $oDownloadSamplesSelect = _IEGetObjById($oIE, "language") _IEFormElementOptionSelect($oDownloadSamplesSelect, "French", 1, "byText") ;~ _IEFormElementOptionSelect($oDownloadSamplesSelect, "2", 1, "byValue") #CS <html> <head> <div class="form-row"> <div class="col-7"> <label>Language</label> <select name="language" class="select" id="language"> <option value="1">English</option> <option value="2">French</option> <option value="3">German</option> <option value="4">Italian</option> <option value="5">Japanese</option> <option value="6">Spanish</option> <option value="7">Russian</option> <option value="8">Hindi</option> <option value="9">Arabic</option> <option value="10">Chinese</option> <option value="11">Dutch</option> <option value="12">Finnish</option> <option value="13">Korean</option> <option value="14">Norwegian</option> <option value="15">Portuguese</option> <option value="16">Romanian</option> <option value="17">Serbian</option> <option value="18">Croatian</option> <option value="20">Polish</option> <option value="21">Afar</option> <option value="22">Abkhazian</option> <option value="23">Afrikaans</option> <option value="24">Amharic</option> <option value="25">Assamese</option> <option value="26">Aymara</option> <option value="27">Azerbaijani</option> <option value="28">Bashkir</option> <option value="29">Belarusian</option> <option value="30">Bulgarian</option> <option value="31">Bihari</option> <option value="32">Bislama</option> <option value="33">Bengali/Bangla</option> <option value="34">Tibetan</option> <option value="35">Breton</option> <option value="36">Catalan</option> <option value="37">Corsican</option> <option value="38">Czech</option> <option value="39">Welsh</option> <option value="40">Danish</option> <option value="41">Bhutani</option> <option value="42">Greek</option> <option value="43">Esperanto</option> <option value="44">Estonian</option> <option value="45">Basque</option> <option value="46">Persian</option> <option value="47">Fiji</option> <option value="48">Faeroese</option> <option value="49">Frisian</option> <option value="50">Irish</option> <option value="51">Scots/Gaelic</option> <option value="52">Galician</option> <option value="53">Guarani</option> <option value="54">Gujarati</option> <option value="55">Hausa</option> <option value="56">Hungarian</option> <option value="57">Armenian</option> <option value="58">Interlingua</option> <option value="59">Interlingue</option> <option value="60">Inupiak</option> <option value="61">Indonesian</option> <option value="62">Icelandic</option> <option value="63">Hebrew</option> <option value="64">Yiddish</option> <option value="65">Javanese</option> <option value="66">Georgian</option> <option value="67">Kazakh</option> <option value="68">Greenlandic</option> <option value="69">Cambodian</option> <option value="70">Kannada</option> <option value="71">Kashmiri</option> <option value="72">Kurdish</option> <option value="73">Kirghiz</option> <option value="74">Latin</option> <option value="75">Lingala</option> <option value="76">Laothian</option> <option value="77">Lithuanian</option> <option value="78">Latvian/Lettish</option> <option value="79">Malagasy</option> <option value="80">Maori</option> <option value="81">Macedonian</option> <option value="82">Malayalam</option> <option value="83">Mongolian</option> <option value="84">Moldavian</option> <option value="85">Marathi</option> <option value="86">Malay</option> <option value="87">Maltese</option> <option value="88">Burmese</option> <option value="89">Nauru</option> <option value="90">Nepali</option> <option value="91">Occitan</option> <option value="92">(Afan)/Oromoor/Oriya</option> <option value="93">Punjabi</option> <option value="94">Pashto/Pushto</option> <option value="95">Quechua</option> <option value="96">Rhaeto-Romance</option> <option value="97">Kirundi</option> <option value="98">Kinyarwanda</option> <option value="99">Sanskrit</option> <option value="100">Sindhi</option> <option value="101">Sangro</option> <option value="102">Serbo-Croatian</option> <option value="103">Singhalese</option> <option value="104">Slovak</option> <option value="105">Slovenian</option> <option value="106">Samoan</option> <option value="107">Shona</option> <option value="108">Somali</option> <option value="109">Albanian</option> <option value="110">Siswati</option> <option value="111">Sesotho</option> <option value="112">Sundanese</option> <option value="113">Swedish</option> <option value="114">Swahili</option> <option value="115">Tamil</option> <option value="116">Telugu</option> <option value="117">Tajik</option> <option value="118">Thai</option> <option value="119">Tigrinya</option> <option value="120">Turkmen</option> <option value="121">Tagalog</option> <option value="122">Setswana</option> <option value="123">Tonga</option> <option value="124">Turkish</option> <option value="125">Tsonga</option> <option value="126">Tatar</option> <option value="127">Twi</option> <option value="128">Ukrainian</option> <option value="129">Urdu</option> <option value="130">Uzbek</option> <option value="131">Vietnamese</option> <option value="132">Volapuk</option> <option value="133">Wolof</option> <option value="134">Xhosa</option> <option value="135">Yoruba</option> <option value="136">Zulu</option> <option value="19">Other</option> </select> </div> </main> </body> </html> #CE
    1 point
  6. Hi @Simpel. "Shell.Explorer.2" creates a IE 7.0 embedded browser by default. That might be the reason for the differences. See below: #include <IE.au3> Local $oIE = ObjCreate("Shell.Explorer.2") GUICreate("", 700, 320) GUICtrlCreateObj($oIE, 0, 0, 513, 574) _IENavigate($oIE, "about:blank") $userAgent = $oIE.Document.parentWindow.navigator.userAgent MsgBox(0, "IE ver", StringRegExp($userAgent, "MSIE ([0-9]+.[0-9]+)", 1)[0]) Here is a link that might help you change that: Controlling WebBrowser Control Compatibility Hope this helps you out
    1 point
  7. Hi @jonson1986. First of all, in your code you select the "select" element by id, then try to find "select" elements within it. This results in a empty HTML collection. Also you cannot call focus/OptionSelect on a collection, even if it contained elements. You would need to use a For loop. Finally here is your answer: #include <IE.au3> $site = "http://example.com/upload" $oIE = _IECreate($site) $oDownloadSamplesSelect = _IEGetObjById($oIE, "language") _IEFormElementOptionSelect($oDownloadSamplesSelect, "French", 1, "byText") _IEFormElementOptionSelect($oDownloadSamplesSelect, "2", 1, "byValue")
    1 point
  8. Have you considered using _IEBodyReadHTML instead of copying the web page?
    1 point
×
×
  • Create New...