盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

网站图片扫描类

时间:2024/11/27作者:未知来源:盾怪网教程人气:

[摘要]"分开)' Fn.Exists:是否有效。0为失效 1 为有效 -1为非本地路径,不能判断。Option ExplicitClass MCScanImgdim File,S...
"分开)
'    Fn.Exists:是否有效。0为失效 1 为有效 -1为非本地路径,不能判断。
Option Explicit
Class MCScanImg
dim  File,ScanType,Conn,Table,ColId,ColImg,FSO,Path,List,ScanText,Spath,Version
dim Folders,Files,TotalSize,Images,Exists,sFiles,Start,EndT,RunTime,DbImg,TotalImg,Filter
Private Sub Class_Initialize
Set File = Server.Createobject("Scripting.Dictionary")
Set FSO = CreateObject("Scripting.FileSystemObject")
ScanType=1
Conn=""
Table=""
ColImg=""
ColId=""
Path ="/"
sPath = Server.MapPath("/")
List=0
ScanText="asp/htm/html"
Folders=0
Files=0
TotalSize=0
Images=0
DbImg=0
Exists=0
sFiles=0
TotalImg=0
Start=Timer
Endt=Timer
Runtime=0
Filter="src=http://www.okasp.com/techinfo/(.[^/>^/&]*)(.gif.jpg)"
Version="1.00"
End Sub

Private Sub Class_Terminate 
Set File=Nothing
Set FSO = Nothing
End Sub

Public Function Scan() '开始扫描
if left(path,1)="/" then
path=Spath&Replace(path,"/","\")
else
Path=Spath&"\"&Replace(path,"/","\")
end if
If ScanType=1 then
Scanfile(Path)
ElseIf ScanType=2 Then
ScanDb()
Else
ScanFile(Path)
ScanDb()
End If
EndT=timer
RunTime=FormatNumber(EndT-Start)*1000
TotalSize=shb(TotalSize)
TotalImg=DbImg+Images
End Function

Private Sub ScanDB() '扫描数据库。这里的路径难于判断,请在InsDb中更改(If AddNum=0 后)
Dim Rs,RetStr,ReBel,SQL
SQL="Select "&ColID&","&ColIMG&" From "&Table&" Order by "&ColID&" DESC"
'On Error Resume Next
If Conn ="" OR Table="" OR ColID="" OR ColIMG = "" Then
Exit Sub
Else
Set Rs = Server.CreateObject("ADODB.RecordSet")
Rs.Open SQL,conn,3,3

While Not Rs.EOF
RetStr=Rs(1)
ReBel="表"&Table&"中的"&ColImg&"列(ID:"&Rs(0)&")"
InsDb RetStr,ReBel,0,""
Rs.MoveNext
Wend
Rs.Close
Set Rs=Nothing
End If
End Sub

Private Sub ScanFile(PathStr) '扫描文件。递归
Dim f,ff,fn,fd,fdn,RealPath,fr,fc
'Response.write PathStr&"<br>"
Set ff = fso.getfolder(pathstr)
Set f = ff.files
Set fd = ff.subfolders
If f.Count >0 Then
For Each fn In f
Files=Files+1
TotalSize=TotalSize+fn.Size
If ChkFileName(fn.Name) Then
sFiles=sFiles+1
If Right(PathStr,1) <> "\" Then
RealPath=PathStr&"\"&fn.Name
Else
RealPath=PathStr&fn.Name
End If
Set fr = FSO.OpenTextFile(RealPath,1)
fc=fr.ReadAll
'response.write RealPath&"<br>"
RegExpTest filter,fc,RealPath
End If
Next
End If

If fd.Count> 0 Then
For Each fdn In fd
Folders=Folders+1
dim temp
if right (PathStr,1) <> "\" then
temp=PathStr&"\"&fdn.Name
else
temp=PathStr&fdn.Name
end if
ScanFile(temp)
Next
End If
End Sub

Private Sub RegExpTest(Patrn, Strng,PathStr) '查找图片
  Dim RegEx, Match, Matches,Chk,ReImg,RetStr,ReBel,TheFile
  Set RegEx = New RegExp
  RegEx.Pattern = Patrn 
  RegEx.IgnoreCase = True
  RegEx.Global = True
  Set Matches = RegEx.Execute(Strng)
  For Each Match in Matches 
    RetStr = Replace(Match.Value,"src=","")
 RetStr = Replace(RetStr,"'","")
 RetStr = Replace(RetStr,"""","")
 Chk = 0
 
 ReBel=GetFn(PathStr)
 InsDb RetStr,ReBel,1,PathStr
  Next
End Sub

Private Function GetExt(FullPath) '获得文件扩展名,用于判断是否是扫描的文件类型
Dim Temp
If FullPath <> "" Then
Temp = Mid(FullPath,InStrRev(FullPath, "\")+1)
If InStr(Temp,".")>0 Then
GetExt=Mid(Temp,InStrRev(Temp, ".")+1)
Else
GetExt=Temp
End If
Else
GetExt = ""
End If
End  Function

Private Function ChkFileName(Str) '检测文件是否是要扫描的文件类型
Dim ar,i,fn
fn=GetExt(str)
ar=Split(ScanText,"/")
ChkFileName=False
For i=0 To ubound(ar)
If lCase(fn) =lCase(Trim(ar(i))) Then
ChkFileName=True
Exit Function
End If
Next
End Function

Private Function shb(n) '显示字节数
If n<1024 Then
shb = n&"字节"
ElseIf n>1024 and n<1024*1024 Then
shb = formatnumber(n/1024,2)&"K"
ElseIf n>=1024*1024 and n <1024*1024*1024 Then
shb = formatnumber(n/(1024*1024),2)&"M"
Else
shb =formatnumber(n/(1024*1024*1024),2)&"G"
End If
End Function

Private Sub InsDb(RetStr,ReBel,AddNum,PathStr) '分析图片是否有效,并添加到字典对象中
dim chk,ReImg,TheFile
If InStr(RetStr,"http://")>0 OR Instr(RetStr,"ftp://")>0 Then
ReImg=RetStr
Chk=-1
Else
RetStr = Replace(RetStr,"/","\")
If (Left(RetStr,1) = "\" ) Then
RetStr=SPath&Retstr
ElseIf Left(RetStr,3) = "..\" Then
dim temp
temp=GetPath(PathStr)
Do Until Left(RetStr,3) <> "..\"  '处理相对路径
Temp=Fso.GetParentFolderName(Temp)
RetStr=Mid(RetStr,4,len(RetStr)-3)
Loop
RetStr=Temp&"\"&RetStr
Else
If AddNum=0 Then
if left(RetStr,1)="\" then
RetStr=Path&"\"&Retstr
Else
RetStr=path&Retstr
End If
else
RetStr=getpath(Pathstr)&RetStr
End IF
End If

If FSO.FileExists(RetStr) Then
Chk=1
End If
ReImg=GetFn(RetStr)
End If 
If Chk=0 Then
Exists=Exists+1
End if
If File.Exists(ReImg) then
Set TheFile=File.Item(ReImg)
If TheFile.Belong <> ReBel Then
TheFile.Belong=TheFile.Belong&"

关键词:网站图片扫描类




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版