wraithdu Posted September 10, 2008 Share Posted September 10, 2008 (edited) I was curious after seeing another example for using TCP to remotely set a computer's volume. I wanted to try sending files as well, and this is what I came up with. The server will take a screencap and send it to the client. Current settings allow it to run on one computer, for testing purposes. Modify the IP addresses for your needs. It could easily be extended to send / receive any kind of file, like a remote file retrieval system. Two parts, server and client. UPDATE - Small, added ability for the server to send the cap back to the client by determining the connected IP address (I had to fix the SocketToIp() function from the helpfile first). Also added a timeout to the client so in case the capture connection fails, it won't sit in a loop forever. UPDATE2 - Optimized the file read / send / write based off SoulA's implementation. Thanks! UPDATE3 - Totally rewritten. Now it reuses the same connection for all sending and receiving, so SocketToIp() is not needed. Also uses pre-shared keys for RC4 encryption and authentication, and MD5 to check the received data's integrity. Thanks to Ward for the RC4 and MD5 functions. Place a file called "tcp_key.bin" in the same directory as the scripts as the pre-shared key. You can use any file, but I'd suggest something not too big. My test key was 1024 bytes (1 K) created with OpenSSL as random data.TCP_with_MD5_Screencap_client.au3TCP_with_MD5_Screencap_server.au3 Edited January 18, 2009 by wraithdu Link to comment Share on other sites More sharing options...
SoulA Posted September 10, 2008 Share Posted September 10, 2008 (edited) Interesting approach yet simple code I like it. Might take some concepts for myself. Here is a UDF that I wrote for sending and receiving files. I made it for a RAT program I am working on and I also use it to transfer screen captures. I think it works pretty well. Just to note the sendPacket() function is just sending a packet with error checking so replacing it with TCPSend() would work just the same. expandcollapse popupFunc sendFile($file, $delete = 0) $FileOpen = FileOpen($file, 16) ;open in binary $FileSize = FileGetSize($file) $BytesSent = 0 sendPacket(String($FileSize)) ;send hte file size initially so other program and do progress bars and such sleep(100) While $BytesSent < $FileSize ;control to stop the loop and stop sending $ReadFile = FileRead($FileOpen, 4096) $BytesSent += TCPSend($socket, $ReadFile) ;adds bytes to know when to stop the loop If @error Then FileClose($FileOpen) If $delete = 1 Then FileDelete($file) connFail() EndIf sleep(20) ;allows other computer time to write to file can be adjusted accordingly WEnd sleep(20) sendPacket("Transfer Complete") ;lets other computer know we are done sending FileClose($FileOpen) If $delete = 1 Then FileDelete($file) $timeout = TimerInit() ;resets global time EndFunc Func getFile($file, $delete = 0) Local $time = 0 $file = FileOpen($file, 18) ;open in binary $time = TimerInit() ;starst a timeout timer so we aren't trying to send forever Do $recv = TCPRecv($socket, 17520) $dif = TimerDiff($time) If $dif >= 60000 Then ;one minute If $delete = 1 Then ;deletes the file if connection fails FileClose($file) FileDelete($file) EndIf connFail() ;timeout UDF to kill the application and close GUIS EndIf sleep(1) If $recv <> "Transfer Complete" Then FileWrite($file, $recv) Until $recv = "Transfer Complete" FileClose($file) $timeout = TimerInit() ;resets global time EndFunc Edited September 10, 2008 by SoulA Link to comment Share on other sites More sharing options...
jaenster Posted September 10, 2008 Share Posted September 10, 2008 Nice to add SoulA -jaenster Link to comment Share on other sites More sharing options...
wraithdu Posted September 10, 2008 Author Share Posted September 10, 2008 Small updates to scripts. Thanks SoulA for the tips! Link to comment Share on other sites More sharing options...
SoulA Posted September 10, 2008 Share Posted September 10, 2008 you fixed SocketToIP... sweet Link to comment Share on other sites More sharing options...
Adam1213 Posted October 4, 2008 Share Posted October 4, 2008 The fixed SocketToIp function should be included with autoitscript IRC Client - 75 pages 3728 lines. Blob crumbler (game)Backup (drag to backup + cmd line)RS232 Link to comment Share on other sites More sharing options...
Xwolf Posted December 31, 2008 Share Posted December 31, 2008 Good job. Thanks for your works. Link to comment Share on other sites More sharing options...
sisu Posted January 14, 2009 Share Posted January 14, 2009 good giob Link to comment Share on other sites More sharing options...
MrBlue Posted January 14, 2009 Share Posted January 14, 2009 thanks i'll check it out should be usefull also nice to find an open source community, Link to comment Share on other sites More sharing options...
rasim Posted January 14, 2009 Share Posted January 14, 2009 (edited) @wraithduNice scripts my friend! Thanks for sharing Edited January 14, 2009 by rasim Link to comment Share on other sites More sharing options...
wraithdu Posted January 14, 2009 Author Share Posted January 14, 2009 Thanks! Actually I've got a better version sitting around that uses pre-shared keyfile authentication for the initial connection, then RC4 encryption and MD5 checksumming for the actual file transfer. I'll post it up when I get home. Link to comment Share on other sites More sharing options...
wraithdu Posted January 18, 2009 Author Share Posted January 18, 2009 New version posted. 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