Lakes Posted May 21, 2006 Share Posted May 21, 2006 #include <GUIConstants.au3> ; == GUI generated with Koda ==); $NetGUI = GUICreate("NetStat", 494, 44, 209, 213) $Stats = GUICtrlCreateLabel("Stats", 8, 8, 376, 24, BitOR($SS_SUNKEN,$WS_GROUP)) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) While 1 $Netlog = "C:\netstat.log" Run(@comspec & " /c netstat -e > C:\netstat.log", @SystemDir, @SW_HIDE) $Netst = FileOpen($Netlog, 0) $NetStat = FileReadLine($Netst,5) GUICtrlSetData ( $Stats, $NetStat ) sleep(500) $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE FileClose ($Netlog) ExitLoop Case Else ;;;;;;; EndSelect WEnd Exit Is possible to read the output of the netstat command directly instead of having to create a file? Thanks. 2015 - Still no flying cars, instead blankets with sleeves. Link to comment Share on other sites More sharing options...
BigDod Posted May 21, 2006 Share Posted May 21, 2006 Check This out it may help. Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
Lakes Posted May 22, 2006 Author Share Posted May 22, 2006 I worked it out...#include <GUIConstants.au3> #include <Constants.au3> ; == GUI generated with Koda ==); $NetGUI = GUICreate("NetStat", 494, 44, 209, 213) $Stats = GUICtrlCreateLabel("Stats", 8, 8, 376, 24, BitOR($SS_SUNKEN,$WS_GROUP)) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) While 1 $NetStat = Run(@comspec & " /c netstat -e", @SystemDir, @SW_HIDE,2) $Line = StdOutRead ($NetStat,130) $Line = StringTrimLeft ($Line, 100) GUICtrlSetData($Stats,$Line) Sleep(500) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd 2015 - Still no flying cars, instead blankets with sleeves. Link to comment Share on other sites More sharing options...
w0uter Posted May 22, 2006 Share Posted May 22, 2006 cool. i also did this once. ill post my code when i get home. My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
Lakes Posted May 22, 2006 Author Share Posted May 22, 2006 (edited) cool. i also did this once. ill post my code when i get home. Cool, here`s what I have so far. #include <GUIConstants.au3> #include <Constants.au3> #include <GUIConstants.au3> ; == GUI generated with Koda ==); $NetGUI = GUICreate("NetStats", 353, 69, 188, 141) GUICtrlCreateLabel("Uploaded", 8, 8, 73, 20, $WS_GROUP) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Upload = GUICtrlCreateLabel("Upload", 8, 32, 137, 20, BitOR($SS_SUNKEN,$WS_GROUP)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlCreateLabel("Downloaded", 176, 8, 91, 20, $WS_GROUP) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Download = GUICtrlCreateLabel("Download", 176, 32, 161, 20, BitOR($SS_SUNKEN,$WS_GROUP)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) While 1 $NetStat = Run(@comspec & " /c netstat -e", @SystemDir, @SW_HIDE,2) $Line = StdOutRead ($NetStat,130) $Line = StringTrimLeft ($Line, 103) $Lines = StringSplit($Line," ") GUICtrlSetData($Download,$Lines[2]) GUICtrlSetData($Upload,$Lines[8]) Sleep(500) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd Edited May 22, 2006 by Lakes 2015 - Still no flying cars, instead blankets with sleeves. Link to comment Share on other sites More sharing options...
w0uter Posted May 22, 2006 Share Posted May 22, 2006 i did it like this. you might have to change the StringReplace part with your own language. Opt("GUIOnEventMode", 1) ProcessSetPriority(@AutoItPID, 5) GuiCreate("Stats", 410, 180, -1, -1, -1, 8) GUISetOnEvent(-3, '_exit') $h_Edit = GuiCtrlCreateEdit("", 10, 10, 390, 160, 0) GUICtrlSetFont(-1, 9, 400, 0, 'Courier New') GuiSetState() While 1 $i_Pid = Run('netstat.exe -e', '', @SW_HIDE, 2) $s_Txt = '' While Not @error $s_Txt &= StdoutRead($i_Pid) WEnd Sleep(500) GUISetState(@SW_LOCK, $h_Edit) GUICtrlSetData($h_Edit, StringReplace($s_Txt, 'Ontvangen Verzonden', ' Ontvangen Verzonden')) GUISetState(@SW_UNLOCK, $h_Edit) WEnd Func _exit() Exit EndFunc My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
Lakes Posted May 22, 2006 Author Share Posted May 22, 2006 I took out the string replace as it was`nt making any difference to the output. Opt("GUIOnEventMode", 1) ProcessSetPriority(@AutoItPID, 5) GuiCreate("Stats", 410, 180, -1, -1, -1, 8) GUISetOnEvent(-3, '_exit'); <-------------------Is -3 same as putting $GUI_EVENT_CLOSE here? $h_Edit = GuiCtrlCreateEdit("", 10, 10, 390, 160, 0) GUICtrlSetFont(-1, 9, 400, 0, 'Courier New') GuiSetState() While 1 $s_Txt = '' $i_Pid = Run('netstat.exe -e', '', @SW_HIDE, 2) While Not @error $s_Txt &= StdoutRead($i_Pid); <-- Ah, this adds text to the string, very good! WEnd Sleep(500) GUISetState(@SW_LOCK, $h_Edit); <-- don`t make any difference to the output? GUICtrlSetData($h_Edit, $s_Txt); <- removed the text, as it was`nt in the output. GUISetState(@SW_UNLOCK, $h_Edit) WEnd Func _exit() Exit EndFunc Like the GUISetOnEvent, I`ll use that! 2015 - Still no flying cars, instead blankets with sleeves. Link to comment Share on other sites More sharing options...
Lakes Posted May 23, 2006 Author Share Posted May 23, 2006 (edited) expandcollapse popup#include <GUIConstants.au3> #include <Constants.au3> Opt("GUIOnEventMode", 1) ; == GUI generated with Koda ==); $NetGUI = GUICreate("NetStats", 293, 190, 195, 148) GUICtrlCreateLabel("Uploaded", 8, 8, 73, 20, $WS_GROUP) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $UpLoad = GUICtrlCreateLabel("Upload", 8, 32, 100, 20, BitOR($SS_SUNKEN,$WS_GROUP)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlCreateLabel("Downloaded", 176, 8, 91, 20, $WS_GROUP) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Download = GUICtrlCreateLabel("Download", 176, 32, 105, 20, BitOR($SS_SUNKEN,$WS_GROUP)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Up = GUICtrlCreateLabel("TodayUp", 8, 96, 100, 20, BitOR($SS_SUNKEN,$WS_GROUP)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Down = GUICtrlCreateLabel("TodayDown", 176, 96, 100, 20, BitOR($SS_SUNKEN,$WS_GROUP)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlCreateLabel("Today", 8, 72, 49, 20, $WS_GROUP) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Reset = GUICtrlCreateButton("Reset", 104, 156, 73, 25) GUICtrlSetOnEvent ( $Reset, "_reset" ) GUISetOnEvent(-3, "_exit") GUISetState(@SW_SHOW) $UpStr = 0 $DownStr = 0 $Tup = 0 $Tdwn = 0 _netstat($UpStr,$DownStr); Get inital values $Tup = $UpStr $Tdwn = $DownStr While 1 _netstat($UpStr,$DownStr) GUICtrlSetData($Download,$DownStr) GUICtrlSetData($Upload,$UpStr) $TodayUp = $UpStr - $Tup $TodayDown = $DownStr - $Tdwn GUICtrlSetData($Up, $TodayUp) GUICtrlSetData($Down, $TodayDown) Sleep(500) WEnd Func _netstat( ByRef $UpStr, ByRef $DownStr) $NetStat = Run(@comspec & " /c netstat -e", @SystemDir, @SW_HIDE,2) $Line = StdOutRead ($NetStat,130) $Start = StringInStr ( $Line, "Bytes") $Line = StringMid ( $Line, $start + 5 ) $Line = StringStripWS ( $Line, 7 ) $Lines = StringSplit($Line," ") $UpStr = $Lines[2] $DownStr = $Lines[1] EndFunc Func _Reset(ByRef $TUp, ByRef $TDown) _netstat($UpStr,$DownStr) $Tup = $UpStr $Tdwn = $DownStr EndFunc Func _exit() Exit EndFunc Wish there was an option to set the 'ByRef' as default for functions... Edited May 23, 2006 by Lakes 2015 - Still no flying cars, instead blankets with sleeves. Link to comment Share on other sites More sharing options...
Lakes Posted May 26, 2006 Author Share Posted May 26, 2006 This seems to be eating memory and eventually the netstat.exe crashes.. Do i need to add $STDERR_CHILD + $STDOUT_CHILD) to the run comand?? Can someone explain what adding these options do? Thanks. 2015 - Still no flying cars, instead blankets with sleeves. Link to comment Share on other sites More sharing options...
Lakes Posted May 27, 2006 Author Share Posted May 27, 2006 This seems to be eating memory and eventually the netstat.exe crashes.. Do i need to add $STDERR_CHILD + $STDOUT_CHILD) to the run comand?? Can someone explain what adding these options do? Thanks. I`ve changed the code to this:expandcollapse popup#include <GUIConstants.au3> #include <Constants.au3> Opt("GUIOnEventMode", 1) ; == GUI generated with Koda ==); $NetGUI = GUICreate("NetStats", 293, 190, 195, 148) GUICtrlCreateLabel("Uploaded", 8, 8, 73, 20, $WS_GROUP) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $UpLoad = GUICtrlCreateLabel("Upload", 8, 32, 100, 20, BitOR($SS_SUNKEN,$WS_GROUP)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlCreateLabel("Downloaded", 176, 8, 91, 20, $WS_GROUP) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Download = GUICtrlCreateLabel("Download", 176, 32, 105, 20, BitOR($SS_SUNKEN,$WS_GROUP)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Up = GUICtrlCreateLabel("TodayUp", 8, 96, 100, 20, BitOR($SS_SUNKEN,$WS_GROUP)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Down = GUICtrlCreateLabel("TodayDown", 176, 96, 100, 20, BitOR($SS_SUNKEN,$WS_GROUP)) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlCreateLabel("Today", 8, 72, 49, 20, $WS_GROUP) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Reset = GUICtrlCreateButton("Reset", 104, 156, 73, 25) GUICtrlSetOnEvent ( $Reset, "_reset" ) GUISetOnEvent(-3, "_exit") GUISetState(@SW_SHOW) $UpStr = 0 $DownStr = 0 $Tup = 0 $Tdwn = 0 $Line = 0 _netstat($UpStr,$DownStr); Get inital values $Tup = $UpStr $Tdwn = $DownStr While 1 _netstat($UpStr,$DownStr) GUICtrlSetData($Download,$DownStr) GUICtrlSetData($Upload,$UpStr) $TodayUp = $UpStr - $Tup $TodayDown = $DownStr - $Tdwn GUICtrlSetData($Up, $TodayUp) GUICtrlSetData($Down, $TodayDown) Sleep(500) WEnd Func _netstat( ByRef $UpStr, ByRef $DownStr) $NetStat = Run(@comspec & " /c netstat -e", @SystemDir, @SW_HIDE,2) While Not @error $Line &= StdoutRead($NetStat) WEnd $Start = StringInStr ( $Line, "Bytes") $Line = StringMid ( $Line, $Start + 5 ) $Line = StringStripWS ( $Line, 7 ) $Lines = StringSplit($Line," ") $DownStr = $Lines[1] $UpStr = $Lines[2] EndFunc Func _Reset(ByRef $TUp, ByRef $TDown) _netstat($UpStr,$DownStr) $Tup = $UpStr $Tdwn = $DownStr EndFunc Func _exit() Exit EndFunc Which seems more stable, (so far) I need to run it for while. I`d still like to know why this line $Line = StdOutRead ($NetStat,130) seems to eat memory in the old version though... 2015 - Still no flying cars, instead blankets with sleeves. Link to comment Share on other sites More sharing options...
DaveF Posted May 30, 2006 Share Posted May 30, 2006 Which seems more stable, (so far) I need to run it for while.I`d still like to know why this line $Line = StdOutRead ($NetStat,130) seems to eat memory in the old version though... Not certain unless the netstat.exe process was still present as a zombie process after the read. The second function parameter (130 in this case) basically tells StdoutRead not to read more than that many characters. If the read operation is waiting and only 10 characters appear on the pipe, then the function will read and return those characters without waiting for more; this is the behavior of the underlying Win32 API function, incidentally, not just something that StdoutRead is imposing on you. You'll find that with buffered console I/O it's more often the case that it's multiple small writes that create an app's output rather than a single blurt of the whole output. If you have a sizable network then the output of netstat could be more than the process's output buffer would hold, and without multiple calls to StdoutRead to empty the buffer the netstat process would block (hang) in the middle of the write process that maxed-out the output buffer and be a possible cause of your memory issue. Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines. 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