7

我正在寻找通过日志解析器查询从 IIS 日志文件的用户代理字段中找出浏览器名称和版本、操作系统名称和版本。

由于 User-Agent 字符串对于每个浏览器和设备都有不同的格式,我如何通过日志解析器查询从每个字符串中准确获取浏览器名称和版本?实际上是将完整的 UA 字符串存储在 db 表中。那么 SQL 中是否有任何其他函数可以从存储的字段值中获取浏览器和版本号?

我试过这个查询来查找浏览器名称:

SELECT top 100 case strcnt(cs(user-agent), 'Firefox') 
when 1 THEN 'Firefox'  
else 
case strcnt(cs(user-agent), 'MSIE+6') 
when 1 THEN 'IE 6' 
else 
case strcnt(cs(user-agent), 'MSIE+7') 
when 1 THEN 'IE 7' 
else case strcnt(cs(user-agent), 'Chrome') 
when 1 THEN 'Chrome' 
else case strcnt(cs(user-agent), 'MSIE ') 
when 1 THEN 'IE' 
else case strcnt(cs(user-agent), 'Safari ') 
when 1 THEN 'Safari' 
else case strcnt(cs(user-agent), 'Opera ') 
when 1 THEN 'Opera' 
ELSE 'Unknown' 
End End End End End End End as Browser

Log Parser 或 SQL 中是否有任何其他功能可用于获取浏览器名称?以及如何获得浏览器版本?

4

2 回答 2

6

如果您想从 IIS 日志文件中获取用户代理的详细信息,您需要使用日志解析器。您可以使用以下查询来获取用户代理。

SELECT  
    cs(User-Agent) As UserAgent,  
    COUNT(*) as Hits  
FROM c:\inetpub\logs\LogFiles\W3SVC1\*  
GROUP BY UserAgent  
ORDER BY Hits DESC

希望您已安装 LogParser 如果未安装请从此处安装并尝试使用以下方式

LogParser.exe -i:W3C "Query" -o:CSV

它将生成类似于以下内容的输出

UserAgent   Hits
iisbot/1.0+(+http://www.iis.net/iisbot.html)    104
Mozilla/4.0+(compatible;+MSIE+8.0;… 77
Microsoft-WebDAV-MiniRedir/6.1.7600 23
DavClnt

您可以从这里阅读更多内容。

于 2013-07-23T04:55:08.040 回答
3
select distinct
    case strcnt(cs(user-agent),'Chrome') when 1 THEN 'Chrome'
    else case strcnt(cs(user-agent),'Firefox') when 1 THEN 'Firefox'
    else case strcnt(cs(user-agent),'MSIE+6') when 1 THEN 'IE 6'
    else case strcnt(cs(user-agent),'MSIE+7') when 1 THEN 'IE 7'
    else case strcnt(cs(user-agent),'MSIE+8') when 1 THEN 'IE 8'
    else case strcnt(cs(user-agent),'MSIE+9') when 1 THEN 'IE 9'
    else case strcnt(cs(user-agent),'MSIE+10') when 1 THEN 'IE 10'
    else case strcnt(cs(user-agent),'IE+11') when 1 THEN 'IE 11'
    else case strcnt(cs(user-agent),'+rv:11') when 1 THEN 'IE 11'
    else case strcnt(cs(user-agent),'Opera') when 1 THEN 'Opera'
    else case strcnt(cs(user-agent),'Safari/') when 1 THEN 'Safari'
    else case strcnt(cs(user-agent),'iPhone+OS+5') when 1 THEN 'Safari'
    else case strcnt(cs(user-agent),'iPhone+OS+6') when 1 THEN 'Safari'
    else case strcnt(cs(user-agent),'iPhone+OS+7') when 1 THEN 'Safari'
    else case strcnt(cs(user-agent),'CPU+OS+6') when 1 THEN 'Safari'
    else case strcnt(cs(user-agent),'iTunes/11') when 1 THEN 'iTunes'
    else case strcnt(cs(user-agent),'iTunes/10') when 1 THEN 'iTunes'
    else 'Unknown'
    End
    End
    End
    End
    End
    End
    End
    End
    End
    End
    End
    End
    End
    End
    End
    End
    End
    as Browser,
    COUNT(c-ip) as Hits
    FROM '[LOGFILEPATH]'

/* Dont display any cs(User-Agent) which are created by Bots */

WHERE cs(User-Agent) NOT LIKE '%Java%'
AND cs(User-Agent) NOT LIKE '%moodle%'
AND cs(User-Agent) NOT LIKE '%twitter%'
AND cs(User-Agent) NOT LIKE '%mymmu%'
AND cs(User-Agent) NOT LIKE '%MMU%'
AND cs(User-Agent) NOT LIKE '%admant%'
AND cs(User-Agent) NOT LIKE '%contextAd%'
AND cs(User-Agent) NOT LIKE '%bingbot%' 
AND cs(User-Agent) NOT LIKE '%genieo%'
AND cs(User-Agent) NOT LIKE '%proximic%'
AND cs(User-Agent) NOT LIKE '%PageBot%'
AND cs(User-Agent) NOT LIKE '%feedfetcher%'
AND cs(User-Agent) NOT LIKE '%wordpress%'
AND cs(User-Agent) NOT LIKE '%PictureBot%'
AND cs(User-Agent) NOT LIKE '%WeSEE%'
AND cs(User-Agent) NOT LIKE '%Sogou%'
AND cs(User-Agent) NOT LIKE '%msnbot%'
AND cs(User-Agent) NOT LIKE '%Mediapartner%'
AND cs(User-Agent) NOT LIKE '%MagpieRSS%'
AND cs(User-Agent) NOT LIKE '%Affectv%'
AND cs(User-Agent) NOT LIKE '%Nutch%'
AND cs(User-Agent) NOT LIKE '%SkimBot%'
AND cs(User-Agent) NOT LIKE '%WhatWeb%'
AND cs(User-Agent) NOT LIKE '%Googlebot%'
AND cs(User-Agent) NOT LIKE '%Yahoo%'
AND cs(User-Agent) NOT LIKE '%Netcraft%'
AND cs(User-Agent) NOT LIKE '%AhrefsBot%'
AND cs(User-Agent) NOT LIKE '%SemrushBot%'
AND cs(User-Agent) NOT LIKE '%MJ12bot%'
AND cs(User-Agent) NOT LIKE '%DotBot%'
AND cs(User-Agent) NOT LIKE '%Vagabondo%'
AND cs(User-Agent) NOT LIKE '%NetSeer%'
AND cs(User-Agent) NOT LIKE '%PHP%'

/* Dont display any cs(User-Agent) which has an entry of nothing */

AND cs(User-Agent) is NOT NULL

GROUP by Browser
ORDER by Hits DESC
于 2015-04-23T15:18:21.293 回答