风萧萧易水寒 發表於 2020-9-4 23:35:05

vbs源码之的IIS日志分析工具

<p><img title="iis-log-tools" alt="IIS日志分析系统" width="668" height="446" src="https://img.jbzj.com/file_images/article/202009/202009042326041.jpg" /></p>
<p><strong>为什么要开发vbs写的IIS日志分析工具?</strong></p>
<p>在网上找了很多IIS日志分析工具,功能实在太有限,有的仅能分析百度、谷歌等搜索引擎爬虫的来访次数,远远达不到我们的用户的需求。作为一个小站长,有的时候也要分析一下自己站点的广告点击情况,静态页面的还好说,下载类的业务就不好统计了。耗时一晚上写出来本工具分享给大家。</p>
<p><strong>IIS日志分析工具的使用方法</strong></p>
<p>本工具对于初次接收vbs脚本的用户来说,可能有点麻烦。下面我们就一步一步来说说该工具的使用方法。<br />
1、如果 vbscript 默认引擎非cscript,需要修改称cscript。修改方法很简单,直接在运行中输入:</p>
<blockquote>
<p>cscript //Nologo //H:Cscript</p>
</blockquote>
<p>即可切换</p>
<p>2、下载IIS日志分析工具 压缩包<a target="_blank" href="http://xiazai.jb51.net/vbs/vbs-iis-log-jb51.rar">/vbs/vbs-iis-log-jb51.rar</a>,解压,打开log.vbs,修改dbpath为您当前解压的路径。</p>
<p><img title="iis-log-edit" alt="" width="547" height="251" src="https://img.jbzj.com/file_images/article/202009/202009042326052.jpg" /></p>
<p>3、下载您的log日志文件,删掉前三行和第四行的#Fields: ,保存文件名为test.txt,保存到解压目录。</p>
<p><img title="iis-log-data" alt="" width="764" height="700" src="https://img.jbzj.com/file_images/article/202009/202009042326053.jpg" /></p>
<p>4、在开始运行中用cmd命令打开命令提示符,直接把 log.vbs拖拽到命令提示符中,回车即可开始分析。</p>
<p><strong>以后会出软件版本吗?</strong></p>
<p>会的,不过最近不会,其实现在的代码,直接拿到vb中,套个界面就比市面上的iis日志工具强大,但是现在实际还没有成熟,等正式发布时,功能绝对的强大。</p>
<p><strong>IIS日志分析工具是免费的吗?</strong></p>
<p>是的,本工具供站长免费使用,但是传播请保留我们的版权信息。也许您的建议将会出现在我们未来的软件版中。</p>
<p>vbs写的IIS日志分析工具代码如下:</p>
<div class="jb51code">
<pre class="brush:vb;">
'=============================================================
'=       Copyright (c) 2010 猫七(QQ:77068320)   =
'=         All rights reserverd.          =
'=============================================================
'=      IIS日志分析系统 v_1.10.0828         =
'=   使用说明:http://www.miaoqiyuan.cn/p/iis-log-tools=
'=   作者博客:http://www.miaoqiyuan.cn          =
'=   版权声明:本代码供站长免费使用,传播请保留版权信息=
'=============================================================
'=程序简介:在网上找了很多IIS日志分析工具,功能简单,只能 =
'= 分析爬虫来访次数。有时候我们小站长也想分析下广告点击情况 =
'= ,这时候市面上的IIS统计工具就无能为力了。耗时一晚上写出来 =
'= 分享给大家,同时申请落伍,请大家帮顶。          =
'=申请地址:http://www.im286.com/thread-5021543-1-1.html =
'=============================================================
'= 文件:log.vbs                      =
'= 功能:IIS日志分析,懂程序的朋友可扩展,功能不可限量   =
'=============================================================

dbpath = "D:\log"         '日志文件所在目录
tblna = "test.txt"         '日志文件名,如果修改请同时修改 Schema.ini 中相关节点

function getuag(str)
if instr(str,"+MSIE+7.0;")&gt;0 then
getuag = "Internet Explore 7.0"
elseif instr(str,"+MSIE+8.0;")&gt;0 then
getuag = "Internet Explore 8.0"
elseif instr(str,"+MSIE+6.0;")&gt;0 then
getuag = "Internet Explore 6.0"
elseif instr(str,"MSIE")&gt;0 then
getuag = "Internet Explore(Other)"
elseif instr(str,"curl")&gt;0 then
getuag = "CUrl"
else
getuag = str
end if
end function

wscript.echo string(60,"=")
wscript.echo "   IIS日志分析工具 By 苗启源(MiaoQiyuan.cn)"
wscript.echo string(60,"=")

set conn = createobject("ADODB.Connection")
conn.open "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &amp; dbpath &amp; ";Extended Properties=""text;HDR=YES;FMT=Delimited;"""

set rs = createobject("ADODB.Recordset")

'统计 链接访问次数
statime = timer()
rs.open "select ,count() from [" &amp; tblna &amp; "] group by ",conn,1,1
ga = rs.getrows()
rs.close
wscript.echo " = 访问次数 = | = 独立访客 = | = 访问路径 = "
wscript.echo string(60,"-")
for i = 0 to ubound(ga,2)
rsid = rsid + 1
tme = ga(1,i)
uri = ga(0,i)

'不支持 COUNT DISTINCT 郁闷,使用笨拙的方法
rs.open "select DISTINCT from [" &amp; tblna &amp; "] where ='" &amp; uri &amp; "'",conn,1,1
aip = rs.recordcount
rs.close

wscript.echo string(10 - len(tme)," ") &amp; tme &amp; "| " &amp; string(8 - len(aip)," ") &amp; aip &amp; "   | " &amp; uri
next
wscript.echo string(60,"-")
wscript.echo "统计:" &amp; rsid &amp; "条记录 查询用时:" &amp; formatnumber((timer() - statime) * 1000,3) &amp; "毫秒"
wscript.echo string(60,"-") &amp; vbCrlf


'统计 访问详情
for i = 0 to ubound(ga,2)
rsid = 0
uri = ga(0,i)
wscript.echo string(60,"=")
wscript.echo "   访问详情:" &amp; uri
wscript.echo string(60,"=")
statime = timer()
wscript.echo " = 编号 = | = IP地址 = | = 浏览器类型 = "
rs.open "select DISTINCT , from [" &amp; tblna &amp; "] where ='" &amp; uri &amp; "'",conn,1,1
do while not rs.eof
rsid = rsid + 1
'IP 自动变成了数字,还没有找到解决方法
cip = rs(0)
uag = getuag(rs(1))
wscript.echo string(8 - len(rsid)," ") &amp; rsid &amp; " | " &amp; string(8 - len(cip)," ") &amp; cip &amp; " | " &amp; uag
rs.movenext
loop
rs.close
wscript.echo string(60,"-")
wscript.echo "统计:" &amp; rsid &amp; "条记录 查询用时:" &amp; formatnumber((timer() - statime) * 1000,3) &amp; "毫秒"
wscript.echo string(60,"-") &amp; vbCrlf
next</pre>
</div>
頁: [1]
查看完整版本: vbs源码之的IIS日志分析工具