p)(d Posted January 12, 2009 Share Posted January 12, 2009 i want to check if a tcp connection is established but my code does not work 100% - any help or better ideas? While 1 Sleep(1000) If CheckConnection() Then GUICtrlSetColor($label, 0x00ff00) Else GUICtrlSetColor($label, 0xff0000) EndIf WEnd Func CheckConnection() Local $port = "6510" Local $result = RunWait(@ComSpec & " /c netstat -anop TCP", "", @SW_HIDE ,$STDERR_CHILD + $STDOUT_CHILD) Local $line = StdoutRead($result) Local $result_array = StringSplit($line, @LF) Local $found = False For $i =1 to $result_array[0] If StringInStr($result_array[$i], $port) Then $found = True ExitLoop EndIf Next Return $found EndFunc ;==>CheckConnection SYS 64738 Link to comment Share on other sites More sharing options...
Developers Jos Posted January 12, 2009 Developers Share Posted January 12, 2009 You need to ensure that you retrieve all STDOUT information. Check the helpfile for a good example. 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 More sharing options...
fctd Posted January 12, 2009 Share Posted January 12, 2009 Maybe something like this ? Tring to make an script to detect if I have internet, display a tooltip is no internet but if internet no tooltip.. Gr. [list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font] Link to comment Share on other sites More sharing options...
p)(d Posted January 13, 2009 Author Share Posted January 13, 2009 Thanx Jos, with your tip it works now. but is there a better way? @fctd: i dont want to check if i can reach a system - i want to check if a connection is established SYS 64738 Link to comment Share on other sites More sharing options...
fctd Posted January 13, 2009 Share Posted January 13, 2009 @fctd: i dont want to check if i can reach a system - i want to check if a connection is establishedp)(d, Like this ? ; Start The TCP Services ;============================================== TCPStartUp() ; Connect to a Listening "SOCKET" ;============================================== $socket = TCPConnect( "0.0.0.0", 12345 ) If $socket = -1 Then Exit Else MsgBox(0, "Connected to: ", $socket) EndIf ; Shutdown the TCP connection ;============================================== Func OnAutoItExit() ConsoleWrite("Can't connect =") TCPShutdown() EndFunc [list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font] Link to comment Share on other sites More sharing options...
p)(d Posted January 13, 2009 Author Share Posted January 13, 2009 hi fctd, this script starts a tcpip connection. but in my case a other application starts the connection and i want to use autoit to show if this connection is etablished. p)(d, Like this ? ; Start The TCP Services ;============================================== TCPStartUp() ; Connect to a Listening "SOCKET" ;============================================== $socket = TCPConnect( "0.0.0.0", 12345 ) If $socket = -1 Then Exit Else MsgBox(0, "Connected to: ", $socket) EndIf ; Shutdown the TCP connection ;============================================== Func OnAutoItExit() ConsoleWrite("Can't connect =") TCPShutdown() EndFunc SYS 64738 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 13, 2009 Moderators Share Posted January 13, 2009 (edited) hi fctd,this script starts a tcpip connection.but in my case a other application starts the connection and i want to use autoit to show if this connection is etablished.fctd's idea should work, as "TCPConnect" should only connect if the socket is "already open". Edited January 13, 2009 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
fctd Posted January 13, 2009 Share Posted January 13, 2009 fctd's idea should work, as "TCPConnect" should only connect if the socket is "already open".How are you making a connection ? Greeting. [list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font] Link to comment Share on other sites More sharing options...
p)(d Posted January 13, 2009 Author Share Posted January 13, 2009 (edited) hi fctd,this script starts a tcpip connection.but in my case a other application starts the connection and i want to use autoit to show if this connection is etablished.the server on the other side is always listening!i want to know if my computer has a established connection to this server or not.i can see with sysinternals tcpview fctd's script starts a new tcp connection to my server and shows in every case the "Connected to:" messageon my computer there is a client application (no autoitscript!) that starts the TCP connection and i want to use my script as GUI/monitoringif fctd's "test" would work it would be my favorite solution. Edited January 13, 2009 by p)(d SYS 64738 Link to comment Share on other sites More sharing options...
fctd Posted January 14, 2009 Share Posted January 14, 2009 Ok, Thanks for the explanation. What is the end result? Was placing the "StdoutRead" in a loop enough? Greetings. [list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font] Link to comment Share on other sites More sharing options...
p)(d Posted January 16, 2009 Author Share Posted January 16, 2009 yes, stdout in a loop was the solution for me. SYS 64738 Link to comment Share on other sites More sharing options...
p)(d Posted March 26, 2009 Author Share Posted March 26, 2009 hmm stdout in a loop is no solution if the program runs a lot of days. the memory usage increases and increases... my program is a monitoring tool and it logs the established connections only some idea for keeping the memory usage low? SYS 64738 Link to comment Share on other sites More sharing options...
GEOSoft Posted March 26, 2009 Share Posted March 26, 2009 RunWait() won't accept $STDERR_CHILD + $STDOUT_CHILD. You can only do that with Run() George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
p)(d Posted March 26, 2009 Author Share Posted March 26, 2009 (edited) this is my code: CODEFunc CheckConnection() Local $found = False Local $port = "4234" Local $result = Run(@ComSpec & " /c netstat -anop TCP", "", @SW_HIDE ,$STDERR_CHILD + $STDOUT_CHILD) Local $line While 1 $line = StdoutRead($result) If @error Then ExitLoop Local $result_array = StringSplit($line, @LF) For $i =1 to $result_array[0] If StringInStr($result_array[$i], $port) Then If StringInStr($result_array[$i], "HERGESTELLT") Then $found = True ExitLoop EndIf EndIf Next Wend Return $found EndFunc ;==>CheckConnection Edited March 26, 2009 by p)(d SYS 64738 Link to comment Share on other sites More sharing options...
p)(d Posted March 26, 2009 Author Share Posted March 26, 2009 How are you making a connection ? Greeting.i have a "black box software" on server one with my autoit program for monitoring the connections from server one to server two. SYS 64738 Link to comment Share on other sites More sharing options...
Yashied Posted March 26, 2009 Share Posted March 26, 2009 func _IsInternet() local $Ret = DllCall('wininet.dll', 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0) if (@error) then return SetError(1, 0, 0) endif local $wError = _WinAPI_GetLastError() return SetError((not ($wError = 0)), $wError, $Ret[0]) endfunc; _IsInternet My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... 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