StringRegExp Problem

  • Hallo zusammen

    Wir haben einen Game-Server und leiden unter Hackern, nun möchte ich die Namen in der Log-Datei suchen um so die Ip des Users(Hackers) heraus zu finden um sie dann zu sperren.
    Eine Kollegin hat dieses Pattern geschrieben

    Code
    (?s)SessionManager accepting new connection at ((?:[0-9]{1,3}\.){3}[0-9]{1,3}).*?Client joined \(([a-zA-Z0-9_.-]*?),


    Funktioniert, wenn diese Zeilen mehr oder weniger unmittelbar auf einander folgen, wie bei diesem Beispiel Text.

    Die Namen und Ip's wurden unkenntlich gemacht.

    Code
    20173 - SLOTS - Non-host, no private slots available, will try to use public slot
    20174 - SLOTS - Non-host, no private slots available, will use public slot
    20175 - SessionManager accepting new connection at 01.001.2.79:31521
    20176 - SLOTS - Non-host, no private slots available, will try to use public slot
    20177 - SLOTS - Non-host, no private slots available, will use public slot
    20178 - SessionManager : before : using public slot for new connection with user: d45e5b107576183f (current public open slot: 5) 
    20179 - SessionManager : after : using public slot for new connection (current public open slot: 4) 
    20180 - Client joined (UserDESERT, 0xD45E5B107576183F, 192.168.1.2:0, PeerId: 27, Seq: 239, Data size : 4) - Session ID: 0xAD06D3F5A3006861
    20181 - Game message: UserDESERT connected to the server.
    Code
    20439 - SLOTS - Non-host, no private slots available, will try to use public slot
    20440 - SLOTS - Non-host, no private slots available, will use public slot
    20441 - SessionManager accepting new connection at 01.225.001.15:9007
    20442 - SLOTS - Non-host, no private slots available, will try to use public slot
    20443 - SLOTS - Non-host, no private slots available, will use public slot
    20444 - SessionManager : before : using public slot for new connection with user: 43939f39ea8e26ff (current public open slot: 3) 
    20445 - SessionManager : after : using public slot for new connection (current public open slot: 2) 
    20446 - Game message: User2015 (All): RPf
    20447 - Client joined (UserQueen, 0x43939F39EA8E26FF, 192.168.178.11:0, PeerId: 22, Seq: 242, Data size : 4) - Session ID: 0xAD06D3F5A3006861
    20448 - Game message: UserQueen connected to the server.

    Aber sobald die Zeilen dann so ausehen

    gibt es Fehler.

    Einmal editiert, zuletzt von VinceA (29. Januar 2015 um 13:48)

  • Sehe ich das richtig?: Die IP aus der Zeile ...accepting new connection wird dem User zugewiesen welcher im nächsten Client joined vorkommt?
    Wenn ja dann funktioniert das ganze so ja nur wenn zwischen accepting und joined kein neues accepting dazukommt.
    Selbst wenn man das ganze so umschreibt, dass das accepting dazwischen auch nach seinem User sucht würde es der Logik entsprechend den User vom vorherigen accepting zugewiesen bekommen, da diese dann nunmal der nächste ist.

    Mit einem einfachen RegEx wäre es daher meiner Meinung nach nicht getan, sondern man müsste die accepting und joineds einzeln holen und anhand ihrer Position zusammenführen.
    Also z.B. so:

    [autoit]

    $s_Text = ClipGet()

    [/autoit][autoit][/autoit][autoit]

    $a_IPS = StringRegExp($s_Text, "SessionManager accepting new connection at ((?:\d{1,3}\.){3}\d{1,3})", 3)
    $a_Users = StringRegExp($s_Text, "Client joined \((\w*?),", 3)

    [/autoit][autoit][/autoit][autoit]

    For $i = 0 To UBound($a_IPS) <= UBound($a_Users)? UBound($a_IPS) - 1 : UBound($a_Users) - 1
    ConsoleWrite(StringFormat("% 15s - %-s\n", $a_IPS[$i], $a_Users[$i]))
    Next

    [/autoit]
  • Sehe ich das richtig?: Die IP aus der Zeile ...accepting new connection wird dem User zugewiesen welcher im nächsten Client joined vorkommt?


    Nein nicht immer, so wie in diesem Beispiel

    Spoiler anzeigen

    SessionManager accepting new connection at 00.248.170.001:9002
    6485 - SLOTS - Non-host, no private slots available, will try to use public slot
    6486 - SLOTS - Non-host, no private slots available, will use public slot
    6487 - SessionManager : before : using public slot for new connection with user: 7132c021c663f37a (current public open slot: 2)
    6488 - SessionManager : after : using public slot for new connection (current public open slot: 1)
    6489 - Game message: UserK killed User2015.
    6490 - CNetworkActivityEvent::ConnectionInactivityRaised on client 18
    6491 - Game message: User2012 killed UserK.
    6492 - CNetworkActivityEvent::ConnectionInactivityRaised on client 8
    6493 - Game message: User8227 killed UserM.
    6494 - SLOTS - Non-host, no private slots available, will try to use public slot
    6495 - SLOTS - Non-host, no private slots available, will use public slot
    6496 - SessionManager accepting new connection at 007.104.001.149:9002
    6497 - SLOTS - Non-host, no private slots available, will try to use public slot
    6498 - SLOTS - Non-host, no private slots available, will use public slot
    6499 - SessionManager : before : using public slot for new connection with user: ad505d4f252f81ec (current public open slot: 1)
    6500 - SessionManager : after : using public slot for new connection (current public open slot: 0)
    6501 - Client joined (UserMAD, 0xAD505D4F252F81EC,


    Die roten Zeilen gehören zusammen aber aus ihrgend einem Grund kommt der User nicht durch.
    Die blauen Zeilen gehören zusammen.
    Somit ergibt dein Pattern (Code) und das Pattern der Kollegin 00.248.170.001 - UserMAD statt 007.104.001.149 UserMAD

    Man kann es auch anhand der User Id erkennen welche zusammen gehören

    6487 - SessionManager : before : using public slot for new connection with user: 7132c021c663f37a (current public open slot: 2)

    6499 - SessionManager : before : using public slot for new connection with user: ad505d4f252f81ec (current public open slot: 1)
    6500 - SessionManager : after : using public slot for new connection (current public open slot: 0)
    6501 - Client joined (UserMAD, 0xAD505D4F252F81EC,

    So sieht es im Normalfall aus wenn ein User den Server betritt.

    Spoiler anzeigen

    4218 - SLOTS - Non-host, no private slots available, will try to use public slot
    4219 - SLOTS - Non-host, no private slots available, will use public slot
    4220 - SessionManager accepting new connection at 01.001.202.01:26619
    4221 - SLOTS - Non-host, no private slots available, will try to use public slot
    4222 - SLOTS - Non-host, no private slots available, will use public slot
    4223 - SessionManager : before : using public slot for new connection with user: deac8b99fb16112 (current public open slot: 1)
    4224 - SessionManager : after : using public slot for new connection (current public open slot: 0)
    4225 - Client joined (User1695, 0xDEAC8B99FB16112, 192.168.1.25:0, PeerId: 24, Seq: 49, Data size : 4) - Session ID: 0x20DC0128E74CA1FD
    4226 - Game message: User1695 connected to the server.

  • Na dann versuch mal folgendes Pattern:

    Code
    (?s)SessionManager accepting new connection at ((?:\d{1,3}\.){3}\d{1,3})(?:(?!SessionManager accepting new connection).)+Client joined \((\w*?),
  • Wie schnell die Zeit vergeht.
    AspirinJunkie sry für die späte Antwort, hab dein Pattern getestet , funktioniert bestens in Notepad++ aber leider bei Autoit gibt es ein Crash wenn ich flag 3 oder 4 verwende.

    • Offizieller Beitrag

    Hallo,

    habe gerade mal so probiert

    AutoIt
    #include <array.au3>
    
    
    $szConns = FileRead("conn.txt")
    $aConns = StringRegExp($szConns, "(?s)SessionManager accepting new connection at ((?:\d{1,3}\.){3}\d{1,3})(?:(?!SessionManager accepting new connection).)+Client joined \((\w*?),",3)
    
    
    _ArrayDisplay($aConns)

    als Ergebnis bekomme ich folgendes Array:

  • Hallo bernd670,
    das funktioniert bei mir auch so.
    Wenn ich aber die originale Text Datei benutze die um einiges grösser ist, funktioniert es nicht sobald ich flag 3 oder 4 verwende und mein Script crasht.

    Ich hab dir eine Email gesendet mit einem link um die orignal Datei runterzuladen zum testen.

    • Offizieller Beitrag

    Probiers mal so.


    Edit:

    Probier mal diesen Pattern

    AutoIt
    #include <array.au3>
    
    
    
    
    $szConns = FileRead("FC2_log.txt")
    $aConns = StringRegExp($szConns, "(?s)SessionManager\s+accepting.*?((?:\d{1,3}\.){3}\d{1,3})(?:.(?!SessionManager\s+accepting))+?Client\s+joined\s+\((.*?),", 3)
    
    
    _ArrayDisplay($aConns)


    Der Teil (?:(?!SessionManager accepting new connection).)+ kann bei langen Texten sehr komplex werden, deshalb schmiert das Programm ab, ein (?:(?!SessionManager\s+accepting).??)+ sollte auch gehen.
    Ich habe gesehen das es auch Namen gibt die z. B. einen Punkt beinhalten, dann funktioniert \w*? nicht.