onedayillpay Posted April 1, 2007 Share Posted April 1, 2007 Test.txt netstat -n log file (fake ip) Active Connections Proto Local Address Foreign Address State TCP 192.170.254.1:10595 63.280.202.138:1778 ESTABLISHED TCP 192.170.254.1:6112 4.180.250.234:1667 ESTABLISHED #include <file.au3> Dim $aRecords If Not _FileReadToArray("test.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf For $x = 1 to $aRecords[0] Msgbox(0,'Record:' & $x, $aRecords[$x]) If StringInStr($aRecords[$x][0], '6112') Then SoundPlay(@WindowsDir & "\media\tada.wav",1) EndIf Next the script is supost to FileReadToArray and then im trying to search the file for a line with 6112 but the script crash becuse improper use of stringinstr... Link to comment Share on other sites More sharing options...
gamerman2360 Posted April 1, 2007 Share Posted April 1, 2007 (edited) #include <file.au3> Dim $aRecords If Not _FileReadToArray("test.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf For $x = 1 to $aRecords[0] Msgbox(0,'Record:' & $x, $aRecords[$x]) If StringInStr($aRecords[$x], '6112') Then SoundPlay(@WindowsDir & "\media\tada.wav",1) EndIf NextoÝ÷ ØèÛayø¥y©Ý¶¢Énuì"¶aÆ®¶sbb33c¶æWG7FBÒ'VâgV÷C¶æWG7FBÖâgV÷C²Âv÷&¶ætF"ÂFVfVÇBÂr¢b33c¶&V6÷&G2Ò7G&æu7ÆB7FF÷WE&VBb33c¶æWG7FBÂ5$Äb ¤f÷"b33c·ÒFòb33c¶&V6÷&G5³Ð¢×6v&÷Âb33µ&V6÷&C¢b33²fײb33c·Âb33c¶&V6÷&G5²b33c·Ò¢b7G&ætå7G"b33c¶&V6÷&G5²b33c·ÒÂb33³c"b33²FVà¢6÷VæEÆvæF÷w4F"fײgV÷C²b3#¶ÖVFb3#·FFçvbgV÷C²Ã VæD`¤æW@ Edited April 1, 2007 by gamerman2360 Link to comment Share on other sites More sharing options...
onedayillpay Posted April 1, 2007 Author Share Posted April 1, 2007 Thanks Link to comment Share on other sites More sharing options...
onedayillpay Posted April 2, 2007 Author Share Posted April 2, 2007 (edited) One more little problem, i need to read the hole file before writing, so the some ip isnot logged twice. its like a loop is needed inside of a loop... $netstat = Run("netstat -n", @WorkingDir, Default, 7) $aRecords = StringSplit(StdoutRead($netstat), @CRLF, 1) $file = FileOpen("test.txt",1) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 Sleep(500) For $x = 1 to $aRecords[0] ;Msgbox(0,'Record:' & $x, $aRecords[$x]) If StringInStr($aRecords[$x], '6112') Then $file = FileOpen("test.txt",0) $line = FileReadLine($file);>>>>>>>>>>>>> Right here i need to read the hole file and not the first line if $line = $aRecords[$x] Then MsgBox(0,"tittle","found match") Else $file = FileOpen("test.txt",1) MsgBox(0,"tittle","writeing....") Call("write") EndIf EndIf Next WEnd Func write() FileWriteLine($file, $aRecords[$x]) FileClose($file) EndFunc do until EOF is reached Edited April 2, 2007 by onedayillpay Link to comment Share on other sites More sharing options...
xcal Posted April 2, 2007 Share Posted April 2, 2007 Maybe something like... $netstat = Run("netstat -n", @WorkingDir, @SW_HIDE, 7) $aRecords = StringSplit(StringStripCR(StdoutRead($netstat)), @LF) $file = FileRead('test.txt') For $x = 1 To $aRecords[0] If StringInStr($aRecords[$x], '6112') And Not StringInStr($file, $aRecords[$x]) Then FileWriteLine('test.txt', $aRecords[$x]) Next How To Ask Questions The Smart Way 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