VBS-扫描非法上机的脚本
[size=9pt]Option Explicit'On Error Resume Next
Dim intStartingAddress,intEndingAddress,strSubnet,strComputer,ProName
Dim objShell,strCommand,objExecObject,strText
intStartingAddress = 1 '[/size][size=9pt]设置起始[/size][size=9pt]IP
intEndingAddress = 100 '[/size][size=9pt]设置结束[/size][size=9pt]IP
strSubnet = "192.168.0." '[/size][size=9pt]设置[/size][size=9pt]IP[/size][size=9pt]段前缀[/size][size=9pt]
ProName = "SMENU.exe" '[/size][size=9pt]你要检查的进程名,注意大小写[/size][size=9pt]
Dim Wsh,fso,logfile
Set Wsh = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set logfile = fso.OpenTextFile("[/size][size=9pt]扫描记录[/size][size=9pt].txt",2,True)
logfile.Writeline time&" [/size][size=9pt]开始扫描[/size][size=9pt]"
logfile.WriteBlankLines(1)
Dim i
For i = intStartingAddress to intEndingAddress
strComputer = strSubnet & i
Set objShell = CreateObject("WScript.Shell")
strCommand = "%comspec% /c ping -n 2 -w 500 " & strComputer & ""
Set objExecObject = objShell.Exec(strCommand)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
If Instr(strText, "Reply") > 0 Then
If Not CheckPro(strComputer,ProName) Then
Doit(strComputer)
End If
End If
Loop
Next
logfile.WriteBlankLines(1)
logfile.Writeline time&" [/size][size=9pt]扫描结束[/size][size=9pt]"
logfile.close
Msgbox "[/size][size=9pt]扫描结束[/size][size=9pt]",64,"[/size][size=9pt]扫描结束[/size][size=9pt]"
WScript.quit
Function CheckPro(strComputer,ProName)
Dim objWMIService,colProcesses,objProcess
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")
CheckPro = False
For Each objProcess in colProcesses
If objProcess.Name = ProName Then
CheckPro = True
Exit For
End If
Next
End Function
Sub Doit(strComputer)
logfile.Writeline "[/size][size=9pt]注意[/size][size=9pt] "&strComputer&" [/size][size=9pt]状态异常[/size][size=9pt] "&time
Wsh.popup "[/size][size=9pt]注意[/size][size=9pt] "&strComputer&" [/size][size=9pt]状态异常[/size][size=9pt]",5
End Sub
[/size]
页:
[1]