Jump to content

Remote address output


werter
 Share

Recommended Posts

well i was trying to make a small msg box if i am connecting to a certain "remote adress"

(like it is called when i run cmd and use the command: Netstat -n )

i allready scripted some funny crap painting etc but i dont get allong with the tcpListen() command in AutoIt

how can i tell the proceeding prog:

"when Pc connects to that ip: 123.245.566.776 give me that window:

MsgBox(0, "wusch", "gumpf") "

by the way what does that number after 123.245.566.776:XXX mean ?

my error was allways that TcpListen given me back: -1

thx werter

Link to comment
Share on other sites

  • Developers

by the way what does that number after 123.245.566.776:XXX mean ?

The number after the IPaddress : is the port used.

Not sure what other help we can provide at this moment reading your original post.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I don't see how tcplisten has anything to do with what you want. You really should look up articles on TCP/IP to learn how it works.

You're not going to ever see it connect to those IPs, but anyways

Why not take output from netstat, and parse it to see if it has the desired number? There may be a more direct way to tell if it's connected to a given remote IP, but this would work from the command prompt:

netstat -n |find /c "123.245.566.776"

and tell you the number of lines containing that string.

Look into run or Runwait, and the $STDOUT_CHILD flag, that should let you grab the output from netstat / find

and StdoutRead will let you read it.

Alternativly, instead of using the command line tool "find" to search for the string, you can use the AutoIT StringInStr() command to search for the IP

Edited by TurionAltec
Link to comment
Share on other sites

ok that's more what i was looking 4 but sice i am still a noob in autoit scripting i produced this:

HotKeySet("^!x", "MyExit")
#include <Constants.au3>
$wwhat = 0
for $count = 1 to 500
    
    local $what = Run(@ComSpec & " /c " & 'netstat -n |find /c "127.0.0.1"', "", @SW_HIDE, $STDOUT_CHILD);
    local $wwhat 

    sleep(1000)
    
    $wwhat = StdoutRead($what)
    if $wwhat = 1 then
        MsgBox(0, "Server found", "now joint") 
    endif
    if $wwhat = 1 Then ExitLoop
next
 
Func MyExit()
    Exit
EndFunc

if i do it without the if- condition it works .... but than i get no sence in there .(

and $wwhat gets 1 after: $wwhat = StdoutRead($what)

something is still wrong:P

btw where is the button i can make that thing funny colorull like in autoit ?

Edited by werter
Link to comment
Share on other sites

To highlight code in posts as autoit code, in the post editor press the button on the right that has a white a in a blue box, or just type it it:

msgbox(1,"Title","message")

Back to the issue at hand, One chang eI made was instead of a sleep(1000), I put a ProcessWaitClose, so it will actually wait for the process to finish, instead of guessing when it's finished.

As far as why your expression doesn't work, it's because what is returned from StdoutRead is a string, and not a number. In addition to the number, at the end there's a <CR>and <LF>. You can use the Number() function to extract the numeric expression.

HotKeySet("^!x", "MyExit")
#include <Constants.au3>
$ip = "127.0.0.1"

While 1
    local $PID = Run(@ComSpec & " /c " & 'netstat -n |find /c "' & $ip& '"', "", @SW_HIDE, $STDOUT_CHILD);
    local $NoOfConnections
    ProcessWaitClose($PID)
    $NoOfConnections = number(StdoutRead($PID))
 
 If $NoOfConnections > 0 Then
        MsgBox(64,"Number of connections","There are "& $NoOfConnections & " connections.")
        MsgBox(64,"Showing it's a number", $NoOfConnections & "*33=" & $NoOfConnections*33)
    Else
        MsgBox(48,"Error", "There are no connections to " & $ip)
    EndIf
WEnd

Func MyExit()
    Exit
EndFunc
Edited by TurionAltec
Link to comment
Share on other sites

thank you sooo much you helped me 4 times

1. coding in forum

2. learning the diffrence between string and numeric --> i was going crazy on the fact my " $wwhat " was 1 but not 1

3. giving me 100% what i needed coded

4. helped me completing my own actual script

... i love you XD

how can you give credits in this forum ?

look this is how i finaly handelt it:

HotKeySet("^!x", "MyExit")
#include <Constants.au3>

$what = 0
$wwhat = 0

Do
    $what = Run(@ComSpec & " /c " & 'netstat -n | find /c "213.100.10.150:420"', "", @SW_HIDE, $STDOUT_CHILD)
    ProcessWaitClose($what)
    $wwhat = number(StdoutRead($what))
until $wwhat = 1
    
    MsgBox(0, "Server found", "joint")


Func MyExit()
    Exit
EndFunc 

exit
Edited by werter
Link to comment
Share on other sites

The fact that you read the documentation for the suggested functions, and tried to put together some code shows other posters you are putting an effort into it, which is better than people that come here and simply demand code.

My only comments are:

-Variable names like $what and $wwhat are pretty crappy, undescriptive names. This is a bad programming habit best nipped at the bud. Good variable names will allow the code to half document itself.

-Your condition to exit the loop is when connection count is = 1. There's the possibility it may be greater than one (it may be in the process of closing one to that server and restarting a new connection), so it would be more robust logic to check if the connection count is >0, rather than simply =1

Link to comment
Share on other sites

The fact that you read the documentation for the suggested functions, and tried to put together some code shows other posters you are putting an effort into it, which is better than people that come here and simply demand code.

My only comments are:

-Variable names like $what and $wwhat are pretty crappy, undescriptive names. This is a bad programming habit best nipped at the bud. Good variable names will allow the code to half document itself.

-Your condition to exit the loop is when connection count is = 1. There's the possibility it may be greater than one (it may be in the process of closing one to that server and restarting a new connection), so it would be more robust logic to check if the connection count is >0, rather than simply =1

y thank it was a lot of work you are right and y perhaps $wwhat is bad behavior :) me is a programming noob

y and by expirience the exitloop is ok but you are right > 0 would be better/safer i change that

i was long time running my game in window mode and let cmd run with that one: netstat -n 2 that was crap so i made the script with help from this forum

i hope i can give back what i took here in help

Edited by werter
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...