Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

yay 2 scrips can now talk over tcpip!


  • Please log in to reply
19 replies to this topic
esromneb
  • Members
  • 50 posts
  • Last active: Oct 28 2006 07:02 PM
  • Joined: 06 Jan 2006
Ok here it is folks: my demo for how you can talk inbetween 2 ahk scripts running on 2 computers.

For this to work you gotta have ports open on both sides (if you wanna talk both ways, sorry best I could do)

zips:
http://www.vulnwatch...cat/nc111nt.zip
http://xset.tripod.com/xset551.zip

nc.exe shows up as a "hacktool" with norton. I told it to ignore it somehow (I have norton corp) I can tell you if you want to know.

The computer recieving the message is called the server, the computer sending is called the remote (techincally client but whatever). Just to be clear.

Make a folder on the server
put XSET.exe, XSET32.CMD, nc.exe in the folder

Also you need to make a file (I called it bat.bat)
@echo off
CALL XSET32 string
caller.exe %string%

Also that folder put caller.ahk
tooltip, %1%
Sleep, 1000
You need to compile this file.

open a cmd window, cd to your folder, and run this:
nc.exe -L -p 100 -t -e bat.bat
ovbiously you would run this from an ahk script


next on the remote computer, make a folder, and put nc.exe in it

Also put a txt file like this named command.txt:
yay
A newline at the end of the file is crucial

Still on remote computer, open a cmd window, cd to the folder, and run
nc.exe 192.168.198.129 100 < command.txt
change your ip ovbiously

Ok so a little more info about this setup:
On the server, you would run nc without runwait, b/c it's a server so it idles.
On the remote, you should use runwait.
I haven't actually used this setup in my script yet, so I will have more info about it later.
Idealy you would have one parent script running on the server, and then you would use caller.exe to post/sendmessage to your parent script.
I want + and - FEEDBACK PLEASE!!! Thanks

Maelgwyn (Guest)
  • Guests
  • Last active:
  • Joined: --
OK... I'm new to this kind of thing, is it possible to have both computers as client and server, for mutual communication?

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
So, I was right to recommand netcat for such communication, even thought I didn't tried... :-)
xset is shareware, is it really necessary?
Why do you use it? The site is good on marketing, but poor on instructions...
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

BoBo
  • Guests
  • Last active:
  • Joined: --

xset is shareware, is it really necessary?

Valid point!
Wouldn't it be possible using AHK's native ...

EnvSet
--------------------------------------------------------------------------------
Writes a value to a variable contained in the environment.

EnvSet, EnvVar, Value

Environment Variables vs. "Normal" Variables
Environment variables are maintained by the operating system. You can see a list of them at the command prompt by means of the SET command.

A script may create a new environment variable or change the contents of an existing one with EnvSet. Such additions and changes are private; they are not seen by the rest of the system. However, if a script launches a program (even another script) via Run or RunWait, that program inherits a copy of the parent script's environment variables, including private ones.

To retrieve the contents of an environment variable, reference it just like a normal variable. This relies on the fact that any reference to an undefined or blank variable (e.g. %EmptyVar%) resolves to an empty string unless that variable is defined in the environment (e.g. %ProgramFiles%).

... :?:

esromneb
  • Members
  • 50 posts
  • Last active: Oct 28 2006 07:02 PM
  • Joined: 06 Jan 2006
Bobo, no it's not possible to use EnvSet.

PhiLho, xset is required unless someone is willing to fix the bugs in CMDret. Plus it looks like freeware to me....

Maelgwyn, normally tcp/ip is setup with a server and a client. The server must have a port open and the client connects.

like so: client -> server
The client doesn't need to have any ports open for this to work.

Once the connection is established, data flows both ways like so:
client <-> server

Because AHK can't do ANYTHING with stdin / stdout, it's very hard to use netcat.

The way my setup works is, a connection is made client -> server
and then data only flows client -> server.

THEN THE CONNECTION CLOSES and must be re-opened to send the next bit of data.

Note: you can send as much data as you want, it just has to be ready to send all at the same time.

So Maelgwyn, the short answer to your question is:
if you can open ports on computer A and computer B you can do

A -> B
and
B -> A

at the same time.

I haven't clocked the transmissions but it looks like maybe 1 or 1.5 seconds for each burst of data.

My program might need faster response times, in which case I will devise a multi-port round robin algorithm which would allow for
( 1.5 seconds / n ) delay time where n is reasonably much less that 50

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

PhiLho, xset is required unless someone is willing to fix the bugs in CMDret. Plus it looks like freeware to me....

XSET is a shareware program. Just try it for free (this is a full-featured version - no limitation) and register if you like it. Otherwise, just delete it.

Nothing wrong with shareware, I just wanted to point it out.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Maelgwyn
  • Members
  • 36 posts
  • Last active: May 15 2006 08:45 AM
  • Joined: 13 Jan 2006
Ok... so I've followed the instructions up until the last step:

Still on remote computer, open a cmd window, cd to the folder, and run

Code:

nc.exe 192.168.198.129 100 < command.txt


However, when I do this on the client, it comes up with a message... no available ports.

I think this might have something to do with my IP address. I went to this webpage, http://www.lawrenceg...rograms/ipinfo/ to try and find my IP. Is there any other way to do this?

Or could it be something else?
The rapidity of particle flow alone determines power: LRH

esromneb
  • Members
  • 50 posts
  • Last active: Oct 28 2006 07:02 PM
  • Joined: 06 Jan 2006
I promise I'll get back to you in the mornin, I'm just incapacitated right now.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

I think this might have something to do with my IP address. I went to this webpage, http://www.lawrenceg...rograms/ipinfo/ to try and find my IP. Is there any other way to do this?

You (can) have two IP addresses: the public one, used to communicate with Internet (I have 83.114.xxx.xxx), probably defined by your Internet provider, displayed by the above site, and a private one, used to communicate with other computers on your local network, defined by DHCP (dynamic allocation) or by yourself. If I type ipconfig on the command line, I get 192.168.1.11

That's because I have a router to access Internet.

You should use the former if you want to chat over Internet, and the later to chat on your LAN and do tests.

Note: I found a small, nice script somewhere on this forum:
;--- Ctrl+Alt+I: show IP address
^!i::
	IPFile = %TEMP%\IP
	; Use Netikus service, simple and straight to the point...
	URLDownloadToFile http://www.netikus.net/show_ip.html, %IPFile%
	If ErrorLevel = 1
	{
		MsgBox 16, IP Address, Your public IP address could not be detected.
	}
	FileReadLine IP, %IPFile%, 1
	MsgBox 64, IP Address, Your public IP address is: %IP%`n`nYour private IP address is: %A_IPAddress1%
	FileDelete %IPFile%
Return

Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Maelgwyn
  • Members
  • 36 posts
  • Last active: May 15 2006 08:45 AM
  • Joined: 13 Jan 2006
That is a very nice little script... However, the message, 'No port[s] to connect to' still appears.

Do I have to open or create them somehow?

Thanks again,

Mael.
The rapidity of particle flow alone determines power: LRH

esromneb
  • Members
  • 50 posts
  • Last active: Oct 28 2006 07:02 PM
  • Joined: 06 Jan 2006
Ok, I should have explaned that you can choose any port you want, as long as nc.exe knows which port it is on both computers.

Try this:
Computer A:
nc -l -p 999 -t -e cmd.exe

Computer B:
nc xxx.xxx.xxx.xxx 999

xxx is your ip of course. This script will give you a remote shell. If you do a dir, you will get files on computer A not computer B. As you can see, here I'm using port 999, and you can use any port you want.

Maelgwyn
  • Members
  • 36 posts
  • Last active: May 15 2006 08:45 AM
  • Joined: 13 Jan 2006
That appears to be working. So i would create a script on computer A and somehow have computer B send a message using PostMessage or SendMessage?
The rapidity of particle flow alone determines power: LRH

esromneb
  • Members
  • 50 posts
  • Last active: Oct 28 2006 07:02 PM
  • Joined: 06 Jan 2006
Yes, something like that. I haven't messed around with it, no time.

Maelgwyn
  • Members
  • 36 posts
  • Last active: May 15 2006 08:45 AM
  • Joined: 13 Jan 2006
So once the ports are open... how do I SendMessage to the other comp?

This is what I have for my sendmessage:

SendMessage, 0xC, 0, &chat, Edit4, CC3.ahk

And CC3.AHK is on the other computer

Any help would be appreciated.

Thanks,

Maelgwyn.
The rapidity of particle flow alone determines power: LRH

Maelgwyn
  • Members
  • 36 posts
  • Last active: May 15 2006 08:45 AM
  • Joined: 13 Jan 2006
I had another play around but still couldn't work it out.
The rapidity of particle flow alone determines power: LRH