2011-02-13 56 views
5

平臺:Windows 2003與Perl 我正在研究如何將用戶標識切出IIS日誌文件。然後找出用戶做了什麼。上傳的文件,CWD ..這樣的事情。有[uniqu_ID]用戶ID。如何檢索該ID並搜索它做了什麼。請幫忙。解析Windows Server 2003上的日誌以查找用戶操作

+0

請問您可以發表幾行代碼示例嗎?這個問題似乎很容易,但例子會很好。 – simbabque 2012-04-26 08:33:41

回答

0

Log Parser 2.2

日誌分析器是一個功能強大,用途廣泛 工具,提供了通用查詢 訪問諸如日誌 文件,XML文件和CSV文件基於文本的數據, 以及關鍵數據例如 事件日誌,註冊表,文件 系統和ActiveDirectory®。

+0

我無法在服務器上下載任何內容。我必須與我目前的工作。在Windows 2003上的Perl – Moe 2011-02-13 01:56:19

+0

下載到你的本地盒子,並在那裏處理日誌。 – 2011-02-13 02:05:42

0

我在Windows 2003 Server here上找到了一個IIS日誌文件的例子。不過,請張貼您自己的示例日誌。

192.168.114.201, -, 03/20/01, 7:55:20, W3SVC2, SERVER, 172.21.13.45, 4502, 163, 3223, 200, 0, GET, /DeptLogo.gif, -, 

因爲這不過是一個逗號分隔的文件,所以您有幾種不同的方式可以到這裏。如果您的計算機上安裝了該軟件,則可以使用Text::CSV。如果沒有,這是一個簡單的例子。

use strict; 
use warnings; 
use Data::Dumper; 

my $user = {}; # we will store the actions in here 

# This is what the log file looks like when split into an array 
# 0: Client IP address 
# 1: User name 
# 2: Date 
# 3: Time 
# 4: Service and instance 
# 5: Server name 
# 6: Server IP 
# 7: Time taken 
# 8: Client bytes sent 
# 9: Server bytes sent 
# 10: Service status code 
# 11: Windows status code 
# 12: Request type 
# 13: Target of operation 
# 14: Parameters 

open $log, '<', 'path/to/logfile.log'; 
while (my $line = <$log>) { 
    my @fields = split /, /, $line; # split on comma and space 
    # you'll get an array of actions for each user 
    push @{ $user->{$fields[1]} }, "$fields[12] $fields[13]"; 
    # or more specific: 
# push @{ $user->{$fields[1]} }, { 
#  'time' => $fields[3], 
#  'action' => $fields[12], 
#  'target' => $fields[13], 
# }; 
} 
close $log; 

print Dumper $user; # lets have a look 

# More stuff to do with the data here... 

這是輸出:

$VAR1 = { 
      '-' => [ 
        'GET /DeptLogo.gif' 
       ] 
     }; 

然後你可以去和$user內容寫入到另一個文件,或文件組。

foreach my $u (sort keys %$user) { 
    print "$u\r\n"; 
    foreach $action (@{ $user->{$u} }) { 
    print "$action\r\n"; 
    } 
} 
相關問題