1. 程式人生 > >獲取本地終端電腦有線和無線的IP

獲取本地終端電腦有線和無線的IP

val creat pre exe regexp ins driver ons .com

On Error Resume Next
Dim WshNetwork,con
dim regex,matches

serverIP = Wscript.Arguments(0)
serverDB = Wscript.Arguments(1)
serverUSer = Wscript.Arguments(2)
serverPW = Wscript.Arguments(3)

ConStr = "driver={sql server};Server=" + serverIP + ";Database=" + serverDB + ";uid=" + serverUSer + ";pwd=" + serverPW +";"

set regex = new regexp
pattern = "^.*] "
regex.pattern = pattern

Set WshNetwork = WScript.CreateObject("WScript.Network")
computername = WshNetwork.ComputerName

str = "insert into ipaddress values "

while 1 <> 0
set con = wscript.CreateObject("ADODB.Connection")

con.Open ConStr
command = "delete from ipaddress where computername = ‘" + computername + "‘"
con.Execute(command)

If con.State <> 0 Then
    Set wmiService = GetObject("winmgmts:\\.\root\cimv2")

    Set Items = wmiService.ExecQuery("Select * From Win32_NetworkAdapter")

    command = ""
    For Each objItem in Items
        If LCase(Left(objItem.PNPDeviceID, 4))="pci\" Then
            Set Its = wmiService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration where Caption=‘"& objItem.Caption &"‘")
            For Each It in Its
                If not IsNull(It.MACAddress) Then
                    If not IsNull(It.IPAddress) Then
                        CurrentTime=Year(Now)&"-"&Month(Now)&"-"&day(Now)&" "&Hour(Now)&":"&Minute(Now)&":"&Second(Now)
                        ipAddress = It.IPAddress(0)   
                        nicName = It.Caption
                        nicName = regex.replace(nicName,"")
                        nicMac = It.MACAddress

                        command = str + "(‘"+ computername +"‘,‘" + nicMac +"‘,‘" + ipAddress +"‘,‘" + currenttime  +"‘,‘" + nicName +"‘)"
                        con.Execute(command)    
                    End If
                End If
            Next
        End If
    Next
End If 

con.Close()
WScript.Sleep 10 * 60 * 1000 

wend

獲取本地終端電腦有線和無線的IP