End SyncLock
‘触发另一线程取得机器信息
Dim HostInfo2 As New HostInfo(IMachineIP)
Dim HostThr2 As New Thread(New ThreadStart(AddressOf HostInfo2.sysInfo))
HostThr2.Start()
SyncLock GetType(HostInfoThreadCounter)
HostInfoThreadCounter.counter = 1 ‘启动线程数加1
End SyncLock
End If
SyncLock GetType(StoppCounter)
StopThr.AddStop()
End SyncLock
End Sub
End Class
‘该类只有一个方法,就是将停止的线程数减1
Class StoppCounter
Sub AddStop()
ThreadCounterStopped = ThreadCounterStopped 1
End Sub
End Class
‘此类用于将已有的行插入DataSet
Class AddRow
‘第一个构造函数,以构造好的行为输入参数
Sub New(ByVal row As DataRow)
Try
ds.Tables(0).Rows.Add(row)
Catch ee As Exception
End Try
End Sub
‘第二个构造函数,以机器名用户名等字符串为参数,更新已有的行
Sub New(ByVal IP As String, ByVal user As String, ByVal hostname As String, ByVal Mac As String, ByVal domain As String, ByVal timeout As Char)
Dim RowTimeOut As DataRow
Try
For Each RowTimeOut In ds.Tables(0).Select("IP='" & IP & "'")
RowTimeOut.Item("LastUID") = user
RowTimeOut.Item("Name") = hostname
RowTimeOut.Item("Mac") = Mac
RowTimeOut.Item("Domain") = domain
RowTimeOut.Item("Timeout") = timeout 'Set timeout flag to this item
Exit For 'just run once
Next
Catch er As Exception
End Try
End Sub
End Class
‘由于篇幅限制,这里省略了根据IP取得机器信息的类的代码。
Imports System.Threading ‘用于支持多线程
Imports System.Xml ‘用于分析XML格式的参数文件
Imports System.Data ‘用于保存结果到数据库
Module Module1
Public ds As New DataSet()
Public conn1 As SqlClient.SqlConnection ‘数据库连接
Public ipf As String ‘IP列表文件名
Public dbf As String ‘数据库信息文件
Public ThreadCounterStopped As Integer
Public StopThr As New StoppCounter()
Sub Main() ‘程序主程序
Dim machineIP As String
Dim iplistF As New Xml.XmlDocument()
Dim iplist As Xml.XmlNode
Dim ipitem As Xml.XmlNode
Dim DBinfoF As New Xml.XmlDocument()
Dim DBinfo As Xml.XmlNode
Dim LanID As String
Dim i As Integer
Dim timestart As Integer
Dim ThreadCounterStarted As Integer
ThreadCounterStarted = 0
ThreadCounterStopped = 0
Dim server As String
Dim database As String
Dim uid As String
Dim pwd As String
Dim table As String
Dim connstr, connstr1 As String
Dim ServiceName As String
Dim Purgestr As String
Try
DBinfoF.Load(dbf) ‘读取数据库信息文件
Catch nodb As Exception
MsgBox(nodb.Message & "Wrong DB info file name.")
Exit Sub
End Try
Try
iplistF.Load(ipf) ‘读取IP列表文件
Catch noip As Exception
MsgBox(noip.Message & "Wrong IP list file name.")
Exit Sub
End Try
‘分析数据库信息文件
DBinfo = DBinfoF.ChildNodes(0)
server = DBinfo.ChildNodes(0).InnerText
database = DBinfo.ChildNodes(1).InnerText
uid = DBinfo.ChildNodes(2).InnerText
pwd = DBinfo.ChildNodes(3).InnerText
ServiceName = DBinfo.ChildNodes(4).InnerText
table = DBinfo.ChildNodes(4).Attributes(0).Value
‘根据分析所得,构造连接字符串
connstr1 = "server=" & server & ";database=" & database & ";uid=" & uid & ";password=" & pwd
conn1 = New SqlClient.SqlConnection(connstr1) ‘实例化数据库连接
conn1.Open() ‘打开数据库连接
Dim sa As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("select * from " & table, conn1)
Dim combu As New SqlClient.SqlCommandBuilder(sa)
sa.Fill(ds, table) ‘填充DataSet
ds.Clear() ‘清空旧的数据
Dim IPAddress As String
‘分析IP列表文件
iplist = iplistF.ChildNodes(0)
Dim Ai As Integer
Dim ipexcepCount As Integer
Dim ipexcep As Xml.XmlNode
For Each ipitem In iplist.ChildNodes
Dim Excep(2, 83) As Integer
LanID = ipitem.Attributes(0).Value‘得到网络ID
For i = 2 To 254 ‘从2到254,根据每个网络ID构造IP地址
Ai = 0
‘以下判断是为了跳过保留地址段
If ipitem.HasChildNodes Then
ipexcepCount = ipitem.ChildNodes.Count
ReDim Excep(2, ipexcepCount - 1)
For Each ipexcep In ipitem.ChildNodes
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




