Sign in to follow this  
Followers 0
magician13134

Sending 'MsgBox's via TCP/IP

21 posts in this topic

Often times at school, I'll need to send a message to myself and I don't have a pen to write on my hand, and I dont' check email often enough, so I was thinking about writing a program that I could run from school (maybe even web-based?) and it would send an Autoit MsgBox to my computer... I know NOTHING about the TCPIP commands in Autoit, but I think I know this much:

A program would need to be running on BOTH computers... right?

If I want to password protect the computers, I will need a website that has all IPs/Username with IPs and their passwords, right?

What else do I need to do this? Or if anyone has any very SIMPLE code to help me out, I'd greatly appreciate that, too. Thanks!

Share this post


Link to post
Share on other sites

So, punching a hole through 2 different firewalls seems feasible but e-mailing yourself doesn't?

Share this post


Link to post
Share on other sites

Run this at your comp at home:

;Server Script. RUN FIRST
TCPStartUp()
$MainSocket = TCPListen(TCPNameToIP(@computername), 65432,  100 )
If $MainSocket = -1 Then Exit
While 1
    $ConnectedSocket = TCPAccept( $MainSocket)
    If $ConnectedSocket >= 0 Then
        ExitLoop
    EndIf
Wend
While 1
    $Message=TCPRecv($ConnectedSocket,2048)
    Sleep(25)
    If $Message<>"" Then
        MsgBox(0,"",$Message)
    EndIf
WEndoÝ÷ Ù8^»§¶¬jܨº»%jëh×6;Client Script. RUN SERVER FIRST
TCPStartUp()
$ServerIp="xx.xx.xx.xx";Enter your remote comp's IP here
$MainSocket=TCPConnect($ServerIp, 65432)
If $MainSocket = -1 Then Exit
msgbox(0,"","connected",1)
$Message=InputBox("","Enter the message you wish to send to your computer")
if @error Then Exit
TCPSend($MainSocket,$Message)

You should look for an alternative way of showing the messages, because MsgBox will pause the server and you will only be able to send one message.

You can try it at your own computer. Run the server, then run the client and enter your own IP. Try sending the message and the msgbox should pop up.

You might have lots of trouble with firewalls too...

Share this post


Link to post
Share on other sites

So, punching a hole through 2 different firewalls seems feasible but e-mailing yourself doesn't?

It's not punching a hole in any firewall... you need to be running the program on that computer in order for it to work, and it's no more complicated than a messinging program or an online game.

Oh, and Nahuel, thanks very much, I will try this when I get home!

Share this post


Link to post
Share on other sites

It's not punching a hole in any firewall... you need to be running the program on that computer in order for it to work, and it's no more complicated than a messinging program or an online game.

Well... you will need to punch a hole in your firewall and at school... When you run the server script at home, you'll get a warning asking if you want to unblock it...

Share this post


Link to post
Share on other sites

Hmmm, it doesn't work.... I ran the server, clicked 'Unblock' then 'Allow' then ran the other script after entering my IP from www.whatsmyip.org or whatever (69.133.11.238).... but the second script just closes immediately

Share this post


Link to post
Share on other sites

Hmmm, it doesn't work.... I ran the server, clicked 'Unblock' then 'Allow' then ran the other script after entering my IP from www.whatsmyip.org or whatever (69.133.11.238).... but the second script just closes immediately

Are you trying this on two PC's inside of your school? I'm sure they won't be happy if you are...

Share this post


Link to post
Share on other sites

Hmmm, it doesn't work.... I ran the server, clicked 'Unblock' then 'Allow' then ran the other script after entering my IP from www.whatsmyip.org or whatever (69.133.11.238).... but the second script just closes immediately

You mean the client? If it closes immediately is beacause it can't connect. Are you trying this using your own computer as server and client?

Run the server in your comp, and then run this also in your comp:

;Client Script. RUN SERVER FIRST
TCPStartUp()
$MainSocket=TCPConnect(TCPNameToIP(@ComputerName), 65432)
If $MainSocket = -1 Then Exit
msgbox(0,"","connected",1)
$Message=InputBox("","Enter the message you wish to send to your computer")
if @error Then Exit
TCPSend($MainSocket,$Message)

Share this post


Link to post
Share on other sites

Damn, why not run a simple PHP 'Notepad' script on some free webhost? Seems like a good sime solution for your problem?

Share this post


Link to post
Share on other sites

It's not punching a hole in any firewall... you need to be running the program on that computer in order for it to work, and it's no more complicated than a messinging program or an online game.

Oh, and Nahuel, thanks very much, I will try this when I get home!

It is more complicated than any other messaging program because they all use a "middleman" server where messages are passed through. This bypasses the firewall because there is a constant connection between the clients and said server.

You might be able to forward the necessary ports on your home router but if you are in a dorm you won't have much luck. Also you are assuming the outbound connection isn't being blocked.

Share this post


Link to post
Share on other sites

Hmm... that second script said connected and popped up the input box, but that did nothing.

Both of these computers are at home, but when I checked whatsmyip.org, they moth have the same IP address..... that's kinda weird... or maybe it isn't....

Share this post


Link to post
Share on other sites

Hmm... that second script said connected and popped up the input box, but that did nothing.

Both of these computers are at home, but when I checked whatsmyip.org, they moth have the same IP address..... that's kinda weird... or maybe it isn't....

No no, you are doing it wrong.. Whatismyip.org will tell you your public IP address. The one your ISP gives you. It's the same number for all the computers that are behind your router. Inside your LAN network, you use private IP's. To know the private IP of your PC, use the macro: @IPAddress1 or run cmd.exe and type ipconfig.

Find out what your server computer's IP is (using one of the methos I mentioned above). Run the server script there (you don't need to do any modifications there).

Now go to another computer, edit the client script and add the server's IP. Then run it.

If it works good, you'll get the 'connected' popup and the inputbox. Type whatever you want to say in the inputbox and it should popup in your server computer.

Hope it's clearer now :)

Share this post


Link to post
Share on other sites

try an alternate solution..

run an FTP server at home.. (Make you sure DO NOT use adminstrator/password as the login !!)

The data gets written to INETPUB\ftproot.. or whatever directory you decide on your machine at home..

then use autoit.to read the files.. pop them up and delete them..

all uou need at school or remote anywhere is an FTP client and notepad

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

This is my first go at coding in autoit, please tell me if anything is wrong.

Server:

;Server Script. RUN FIRST
#include <GuiConstants.au3>
$MessageOld = ""
$i = 0
GUICreate("Server Client", 195, 170)
Local $History = GUICtrlCreateEdit("", 10, 10, 175, 150, $ES_READONLY)
GUISetState()

TCPStartUp()
$MainSocket = TCPListen(TCPNameToIP(@computername), 65432,  100 )

If $MainSocket = -1 Then Exit
    While 1
    $ConnectedSocket = TCPAccept( $MainSocket)
    If $ConnectedSocket >= 0 Then
        ExitLoop
    EndIf
Wend

While 1
    $Message=TCPRecv($ConnectedSocket,2048)
    Sleep(25)
    If $Message<>"" Then
        $MessageShow = $MessageOld & $Message
        GuiCtrlSetData($History, $MessageShow)
        $MessageOld = $MessageShow & ", "
    EndIf
WEnd

Few bugs

* When you close the client you have to restart the server

Edited by benscroggs

Share this post


Link to post
Share on other sites

This is my first go at coding in autoit, please tell me if anything is wrong.

It works :)

However, I hope you understand this:

TCPConnect(TCPNameToIP(@ComputerName), 65432)

I made this to test only. This will only work if the same computer is server and client. If you want to do it with two computers, then you must replace TCPNameToIP(@ComputerName) with the IP address of the computer the server is running in.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

It works :)

However, I hope you understand this:

TCPConnect(TCPNameToIP(@ComputerName), 65432)

I made this to test only. This will only work if the same computer is server and client. If you want to do it with two computers, then you must replace TCPNameToIP(@ComputerName) with the IP address of the computer the server is running in.

Yep.

$Ip=InputBox("","Enter the ip of the computer you want to send to",TCPNameToIP(@ComputerName))
$MainSocket=TCPConnect($Ip, 65432)
Edited by benscroggs

Share this post


Link to post
Share on other sites

*sigh* I'm sorry, but I just CAN'T get it working. I got it to work using two computers at my house, on the same router, other than that it won't connect.

So my friend runs it, @IPAddress1 tells him his IP is 192.168.100.100. I enter that into the client script and run it, can't connect. He's not running any firewalls that would block it... any ideas?

Share this post


Link to post
Share on other sites

If your friend is outside your house (on a different LAN) then tell him to go to www.whatismyip.org That IP you are showing us is a private IP, it will only work INSIDE a LAN.

Share this post


Link to post
Share on other sites

Ok, we've tried that too, but let me make sure. He goes there are it says "69.133.11.238"

So does he change the IP part in the server where it's like "TCPNameToIP" for his IP or do we only change the client script?

Share this post


Link to post
Share on other sites

It should work if you use the client to connect to that ip. If it doesn't work, change this line of the server TCPConnect(TCPNameToIP(@ComputerName), 65432) by TCPConnect("69.133.11.238", 65432) and then try to connect with the same ip with the client.

I have also had lots of trouble connecting to other computers outside my LAN. Some of them worked fine, some of them didn't.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0