在大中型企業信息系統中
這個方案使用了Microsoft
一
該程序使用兩個XML格式的配置文件
<IPLIST>
<IP LANID=
<IP LANID=
<IP LANID=
<IP LANID=
<IP LANID=
</IPLIST>
該文件定義將要掃描
<DBINFO>
<SERVER>DBServer</SERVER>
<DATABASE>DB</DATABASE>
<UID>REPORT</UID>
<PWD>REPORT</PWD>
<SERVICE TABLE=
</DBINFO>
該文件定義了連接數據庫所需的信息
TAG Meaning
<SERVER> SCANSERVICE數據庫的服務器名
<DATABASE> SCANSERVICE數據庫名
<UID> 用於更新SCANSERVICE數據庫的數據庫用戶名
<PWD> 用於更新SCANSERVICE數據庫的數據庫用戶的密碼
<SERVICE> 該TAG的 inner 定義了我們希望掃描的Service的名字
Imports System
Imports System
Imports System
Public Class GetStatus
Private IServiceName As String
Private IMachineIP As String
Private ITable As String
Sub New(ByVal Ip As String
IMachineIP = Ip
IServiceName = SvcName
ITable = updatetable
End Sub
Sub GetStausF()
Dim ServiceP As New ServiceController()
ServiceP
ServiceP
Dim myRow As DataRow
Dim status As String
Dim Run As Boolean = False
myRow = ds
Try
If ServiceP
status = ServiceP
Else
Run = True
End If
Catch er As Exception
status = Left(er
If InStr(status
status =
ElseIf InStr(er
status =
End If
End Try
ServiceP
If Not Run Then
myRow(
myRow(
SyncLock GetType(AddRow)
Dim AddRowIns As New AddRow(myRow)
End SyncLock
Dim HostInfo
Dim HostThr
HostThr
SyncLock GetType(HostInfoThreadCounter)
HostInfoThreadCounter
End SyncLock
End If
SyncLock GetType(StoppCounter)
StopThr
End SyncLock
End Sub
End Class
Class StoppCounter
Sub AddStop()
ThreadCounterStopped = ThreadCounterStopped +
End Sub
End Class
Class AddRow
Sub New(ByVal row As DataRow)
Try
ds
Catch ee As Exception
End Try
End Sub
Sub New(ByVal IP As String
Dim RowTimeOut As DataRow
Try
For Each RowTimeOut In ds
RowTimeOut
RowTimeOut
RowTimeOut
RowTimeOut
RowTimeOut
Exit For
Next
Catch er As Exception
End Try
End Sub
End Class
Imports System
Imports System
Imports System
Module Module
Public ds As New DataSet()
Public conn
Public ipf As String
Public dbf As String
Public ThreadCounterStopped As Integer
Public StopThr As New StoppCounter()
Sub Main()
Dim machineIP As String
Dim iplistF As New Xml
Dim iplist As Xml
Dim ipitem As Xml
Dim DBinfoF As New Xml
Dim DBinfo As Xml
Dim LanID As String
Dim i As Integer
Dim timestart As Integer
Dim ThreadCounterStarted As Integer
ThreadCounterStarted =
ThreadCounterStopped =
Dim server As String
Dim database As String
Dim uid As String
Dim pwd As String
Dim table As String
Dim connstr
Dim ServiceName As String
Dim Purgestr As String
Try
DBinfoF
Catch nodb As Exception
MsgBox(nodb
Exit Sub
End Try
Try
iplistF
Catch noip As Exception
MsgBox(noip
Exit Sub
End Try
DBinfo = DBinfoF
server = DBinfo
database = DBinfo
uid = DBinfo
pwd = DBinfo
ServiceName = DBinfo
table = DBinfo
connstr
conn
conn
Dim sa As SqlClient
Dim combu As New SqlClient
sa
ds
Dim IPAddress As String
iplist = iplistF
Dim Ai As Integer
Dim ipexcepCount As Integer
Dim ipexcep As Xml
For Each ipitem In iplist
Dim Excep(
LanID = ipitem
For i =
Ai =
If ipitem
ipexcepCount = ipitem
ReDim Excep(
For Each ipexcep In ipitem
Excep(
Excep(
Ai = Ai +
Next
End If
For Ai =
If i >= Excep(
Console
GoTo SkipIP
End If
Next
machineIP = LanID & i
Dim getSt As New GetStatus(machineIP
Dim GetStThread As New Thread(New ThreadStart(AddressOf getSt
GetStThread
ThreadCounterStarted = ThreadCounterStarted +
Console
If (ThreadCounterStarted Mod
Console
Thread
GC
End If
SkipIP:
Next
Next
Console
Finish:
Thread
GC
If ThreadCounterStopped = ThreadCounterStarted And HostInfoThreadCounter
Dim row As Data
For Each row In ds
row
Next
Purgestr =
Dim com
com
sa
sa
Else
GoTo Finish
End If
End Sub
可以利用如下命令在DOS窗口啟動該程序
Scanservice –i iplist
二
該數據庫保存保存程序運行結果
CREATE TABLE [dbo]
[IP] [varchar] (
[狀態] [varchar] (
[用戶名] [varchar] (
[機器名] [varchar] (
[MAC地址] [varchar] (
[域] [varchar] (
[超時] [varchar] (
[時間安] [DateTime] (
)
三
以上是一個完整的方法
From:http://tw.wingwit.com/Article/program/net/201311/14499.html