RyuHayabusa Posted December 29, 2009 Share Posted December 29, 2009 Greetings,I am new to AutoIt and I never coded with anything network related. Here is what I would like to do: when I receive a specific network packet from a specific IP I would like to execute a specific routine.That routine is already coded, I only need the network part and I have no clue how to create it.I was able to get the packet I need to check with WPE Pro:Can anyone help me out please?Thanks a lot in advance for your help and support. Link to comment Share on other sites More sharing options...
martin Posted December 30, 2009 Share Posted December 30, 2009 Welcome to the AUtoIt forums RyuHayabusa Have you looked at the TCP* functions in the help? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
RyuHayabusa Posted December 30, 2009 Author Share Posted December 30, 2009 Greetings, I tried to open the help in AutoIt previously or looking at previous topics but I was not able to find what I needed. Also when I am in SciTE, if I go to the help menu nothing happens. Do you refer to another help menu maybe? Thanks. Link to comment Share on other sites More sharing options...
darkjohn20 Posted December 30, 2009 Share Posted December 30, 2009 Martin, he wants to get packets from another program. Doesn't the TCP commands only allow communication between other AutoIt scripts? Link to comment Share on other sites More sharing options...
monoceres Posted December 31, 2009 Share Posted December 31, 2009 Martin, he wants to get packets from another program. Doesn't the TCP commands only allow communication between other AutoIt scripts?No. The TCP functions uses the sends the same data as any other client using the TCP protocol. Data is always just data regardless of language or platform. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
darkjohn20 Posted December 31, 2009 Share Posted December 31, 2009 (edited) Oh. So how would you connect to something other than another script that was using TCP? Would you just have to find the right port and listen? Edited December 31, 2009 by darkjohn20 Link to comment Share on other sites More sharing options...
monoceres Posted December 31, 2009 Share Posted December 31, 2009 Yeah, of course you would have to figure out how the data is formatted by the other application, but that's always an issue when dealing with other application. To test, try running this script: TCPStartup() $listen = TCPListen(@IPAddress1,12345) ConsoleWrite(@IPAddress1&@CRLF) While True $socket = TCPAccept($listen) While True $data = TCPRecv($socket,4096) If @error Then ExitLoop ConsoleWrite($data) Sleep(1) WEnd Sleep(1) WEnd Then start cmd and type "telnet YOURIP 12345" (install telnet from control panel if you're on vista+) and start typing things after the connection is enabled. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
darkjohn20 Posted December 31, 2009 Share Posted December 31, 2009 Yeah, I understand it all. Thanks. (Can't be bothered to install Telnet at the moment. I'll just use other programs. I've done it with telnet when I had Vista though. ) Link to comment Share on other sites More sharing options...
RyuHayabusa Posted December 31, 2009 Author Share Posted December 31, 2009 Greetings, Thanks a lot for your help, I was able to trap what packets are coming but how can I see if a specific one (like in my first post) is being received. For instance, from the packet in my first post, what is the information that I should "check" on the listen? Thanks. Link to comment Share on other sites More sharing options...
darkjohn20 Posted December 31, 2009 Share Posted December 31, 2009 (edited) While 1 $Recv = TcpRecv($Listen, $Size) If $Recv <> "" Then ;You got a packet Endif Wend Is that what you mean? Edited December 31, 2009 by darkjohn20 Link to comment Share on other sites More sharing options...
RyuHayabusa Posted December 31, 2009 Author Share Posted December 31, 2009 (edited) Greetings,What I mean is what information on the following packet would I need to check with the "If" clause: Edited December 31, 2009 by RyuHayabusa Link to comment Share on other sites More sharing options...
martin Posted January 1, 2010 Share Posted January 1, 2010 (edited) Greetings, What I mean is what information on the following packet would I need to check with the "If" clause: Do you mean how do you check that you have received that particular packet? If so then you have to make sure that you receive it as binary because if you receive it as a string you will loose the second two strings. The data in that packet is either binary or it is 3 strings because 0x00 is used to mark the end of a string. So if you receive is as a string then you will only see the first one. $stringToFind1 = "GDF|298;3;0" $StringToFind2 = "Im0144" $StringToFind3 = "JX|36;5268960;71741;72385" ; ignore the strings and look for binary data $binaryToFind = Binary('0x4744467C3239383B333B3000496D30313434004A587C33363B353236383936303B37313734313B373233383500') ;or, don't ignore the strings but convert them to binary $binaryToFind = Binary(StringToBinary($stringToFind1) & "00" & STringReplace(StringToBinary($stringToFind2),"0x","") & "00" & StringReplace(StringToBinary($stringToFind3),"0x","") & "00" ) While 1 $Recv = TcpRecv($Listen, $Size,1) If $Recv = $binaryToFind then ;You got the packet exitloop; or dosomething() Endif Wend To extract strings from binary data can be a bit messy, because if you use BinaryToString for binary data which contains more than one string you will get a string which is the length of all the strings but you will only see the first one. So you could do this ;say $Recv is the received binary data $s1 = BinaryToString($Recv) Dim $ss[5] $index = 0 for $n = 1 to stringlen($s1) ;ConsoleWrite(hex(asc(stringmid($s1,$n,1)),2) & @CRLF) if stringmid($s1,$n,1)='' Then $index += 1 if $index > ubound($ss) then Redim $ss[$index+4] Else $ss[$index] &= stringmid($s1,$n,1) EndIf Next for $n = 0 to $index;show the extracted strings ConsoleWrite($ss[$n] & @CRLF) Next EDIT: I might be wrong about receiving the dat as a string. It could be that the string woulb be exactly the same as converting the binary data to a string, but you would still need to extract the strings as I showed, or some better way. If I haven't confused you with this post then I must try harder Edited January 1, 2010 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
RyuHayabusa Posted January 4, 2010 Author Share Posted January 4, 2010 Greetings, Thanks a lot for your help! I will go on from there, to be honest I was busy on the holidays but this is answering my question just fine. I will need to test it and I should be able to debug/modify if needed. Thanks a lot again to all! Link to comment Share on other sites More sharing options...
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