Sign in to follow this  
Followers 0
onedayillpay

_FileReadToArray + StringInStr

5 posts in this topic

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...

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by gamerman2360

Share this post


Link to post
Share on other sites
:whistle: Thanks

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by onedayillpay

Share this post


Link to post
Share on other sites

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

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