码迷,mamicode.com
首页 > 其他好文 > 详细

获取本地终端电脑有线和无线的IP

时间:2019-03-17 23:40:05      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:new   compute   into   mat   insert   cut   lca   current   cond   

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

标签:new   compute   into   mat   insert   cut   lca   current   cond   

原文地址:https://blog.51cto.com/13804335/2364348

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!