Jump to content

Recommended Posts

Posted

Hi there,

i want to write a little program, that read a Logfile and find at the last lines a spezial string.

example:

[11-Sep-20 12:13:29] Open DHCP Server Version 1.75 Windows Build 1052 Starting...
[11-Sep-20 12:13:29] Logging: Normal
[11-Sep-20 12:13:30] Warning: No IP Address for DHCP Static Host 00:ff:a4:0e:ef:99 specified
[11-Sep-20 12:13:30] Warning: No IP Address for DHCP Static Host ff:00:27:78:7b:01 specified
[11-Sep-20 12:13:30] Warning: No IP Address for DHCP Static Host ff:00:27:78:7b:02 specified
[11-Sep-20 12:13:30] Warning: No IP Address for DHCP Static Host ff:00:27:78:7b:03 specified
[11-Sep-20 12:13:30] Default Lease: 36000 (sec)
[11-Sep-20 12:13:30] Server Name: Notebook
[11-Sep-20 12:13:30] Detecting Static Interfaces..
[11-Sep-20 12:13:30] Lease Status URL: http://127.0.0.1:6789
[11-Sep-20 12:13:30] Listening On: 192.168.178.2
[11-Sep-20 12:14:20] Host 34:e3:80:02:fb:60 (geneos) allotted 192.168.178.5 for 360 seconds

 

"[11-Sep-20 12:14:20] Host 34:e3:80:02:fb:60 (geneos) allotted 192.168.178.5 for 360 seconds" is the line i was wating for

from the Line i only need "192.168.178.5"

I need the IP in a var

 

 

 

 

  • Developers
Posted

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

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

  • Developers
Posted
3 minutes ago, GodFlash said:

Hi there,

i want to write a little program, that read a Logfile

Great..so what have you done sofar which isn't working..... Or you want to code it for you for a small fee? ;)

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

Posted

i dont know all functions of the auto it so i have used google to try to code but this seems to be a a realy long way  ....

 

this for example dont return the text inside the log file just return "1"

 

#include <Date.au3>
#include <MsgBoxConstants.au3>

$Date_File = @YEAR&@MON&@MDAY
$FileName = 'C:\OpenDHCPServer\log\OpenDHCPServer' & $Date_File & '.log'
$File_input = FileOpen($FileName, $FO_UTF8)
FileClose($FileName)

 

ConsoleWrite ($File_input)

Posted

At the moment i use a external DHCP-Server where i always need to look at and hit refresh

the IP inside the Log need to replayce the userinterface

Local $IP = InputBox("GenProFa", "Bitte geben Sie den letzten Block der IP ein. Zuletzt bearbeitet", "", " M3")

Run ("C:\Users\GodFlash\Desktop\Neuer Ordner\putty.exe", "", @SW_SHOWMAXIMIZED)

Sleep(300)

$Text = "192.168.178."
ClipPut($Text)
Send('^v')
ClipPut($IP)
Send('^v')
Send("{ENTER}")

 

my problem is i dont know how to extract the string "[11-Sep-20 12:14:20] Host 34:e3:80:02:fb:60 (geneos) allotted 192.168.178.5 for 360 seconds " where i only need the IP "192.168.178.X"

insice the log there will be more then one entry with "host ... allotted 192.16 ..."

just need to extract the last IP i got inside the log.

Posted

Hi.

This should give you a start:

#include <File.au3>
#include <Debug.au3>

$RegEx="(?i)^(.*?)(?:\s)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?:\s)(.*)$"


$LogFile="c:\temp\DHCP-LOG.txt"
Dim $aContent
_FileReadToArray($LogFile,$aContent)
_DebugArrayDisplay($aContent)

for $i = $aContent[0] to 1 step -1
    $aResult=StringRegExp($aContent[$i],$RegEx,3)
    if IsArray($aResult) Then
        _DebugArrayDisplay($aResult,"Line " & $i)
    Else
        ConsoleWrite("Line " & $i & ": no matching for """ & $aContent[$i] & """" & @CRLF)
    EndIf
Next

 

I recognized, that your sample text is offering a URL, that might be constant, opposite to the name of the log file you specified: Maybe reading that HTML document would offer a more reliable approach?

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Posted (edited)

Assuming that the wanted IP is in the text the last one in "192.168.x.x" format, this could work

$txt = "[11-Sep-20 12:13:29] Open DHCP Server Version 1.75 Windows Build 1052 Starting..." & @crlf & _ 
    "[11-Sep-20 12:13:29] Logging: Normal" & @crlf & _ 
    "[11-Sep-20 12:13:30] Warning: No IP Address for DHCP Static Host 00:ff:a4:0e:ef:99 specified" & @crlf & _ 
    "[11-Sep-20 12:13:30] Warning: No IP Address for DHCP Static Host ff:00:27:78:7b:01 specified" & @crlf & _ 
    "[11-Sep-20 12:13:30] 192.168.178.37" & @crlf & _ 
    "[11-Sep-20 12:13:30] Warning: No IP Address for DHCP Static Host ff:00:27:78:7b:02 specified" & @crlf & _ 
    "[11-Sep-20 12:13:30] Warning: No IP Address for DHCP Static Host ff:00:27:78:7b:03 specified" & @crlf & _ 
    "[11-Sep-20 12:13:30] Default Lease: 36000 (sec)" & @crlf & _ 
    "[11-Sep-20 12:13:30] 192.168.178.12" & @crlf & _ 
    "[11-Sep-20 12:13:30] Server Name: Notebook" & @crlf & _ 
    "[11-Sep-20 12:13:30] Detecting Static Interfaces.." & @crlf & _ 
    "[11-Sep-20 12:13:30] Lease Status URL: http://127.0.0.1:6789" & @crlf & _ 
    "[11-Sep-20 12:13:30] Listening On: 192.168.178.2" & @crlf & _ 
    "[11-Sep-20 12:14:20] Host 34:e3:80:02:fb:60 (geneos) allotted 192.168.178.5 for 360 seconds"

; find the position of the last "192.168." sequence
$offset = StringInStr($txt, "192.168.", 0, -1)
; then get the IP from this point
$res = StringRegExp($txt, '[\d.]+', 1, $offset)  
Msgbox(0,"", $res[0])

Edit
Using a keyword preceding the wanted IP works too

$offset = StringInStr($txt, "allotted", 0, -1)

 

Edited by mikell

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
×
×
  • Create New...