我正在寻找通过Log parser查询从IIS日志文件的User Agent字段中找出浏览器名称和版本,操作系统名称和版本。
由于User-Agent字符串对于每个浏览器和设备具有不同的格式,我如何通过日志解析器查询从每个字符串中获取浏览器名称和版本?实际上要在db表中存储完整的UA字符串。 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中是否有其他功能可用于获取浏览器名称?还有如何获得浏览器版本?
答案 0 :(得分:6)
如果您需要IIS日志文件中的用户代理的详细信息,则需要使用Log Parser。您可以使用以下查询来获取用户代理。
SELECT
cs(User-Agent) As UserAgent,
COUNT(*) as Hits
FROM c:\inetpub\logs\LogFiles\W3SVC1\*
GROUP BY UserAgent
ORDER BY Hits DESC
希望您安装了LogParser,如果没有安装,请从here安装并尝试使用以下方式
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
您可以从here了解更多信息。
答案 1 :(得分: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