获取主机名、IP 地址、子网掩码列表

获取主机名、IP 地址、子网掩码列表

想要编写一个Vb脚本来获取已经添加到域控制的计算机的所有主机名、IP地址和子网掩码的完整信息。

答案1

你最好看看微软脚本中心其中大部分内容都是为您编写的。脚本中心有教程以及脚本存储库,Windows 管理员可以在其中共享脚本。您还应该查看 scriptomatic,这是一个可以为您生成 wmi 阅读器代码的 HTA 应用程序

答案2

这是一个经过改编的 VBS 脚本从此页面(寻找“列出 AD 中所有计算机的域、计算机和 IP”):

' Modify these vars to match your enviroment
' requires Windows 2003 DNS

strDomain = "MyWindowsDomain"     ' Windows Domain NetBIOS Name
strDNSSVR = "DNSserver"           ' DNS Server's name or IP
strDNSDomain = ".mydomain.com"    ' Note the . at the beginning!
strFILENAME = "AD-Computers.txt"   ' Output File Name

'------------------------------------------------
'
' File stuff
Dim filesys, testfile 
Set filesys = CreateObject("Scripting.FileSystemObject") 
Set OUTfile= filesys.CreateTextFile(strFILENAME, True)


Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    "Select Name, Location from 'LDAP://" & strDomain & "' " _
        & "Where objectCategory='computer'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst



'debug stuff   Comment if you want to see it during execution
'Wscript.Echo "My DNS Server is: " & strDNSSVR
'Wscript.Echo "My Windows Domain is: " & strDomain
'Wscript.Echo "My DNS Suffix is: " & strDNSDomain
'Wscript.echo "Writing output to File: " & strFILENAME

'output
Do Until objRecordSet.EOF
    strHOST = objRecordSet.Fields("Name").Value
    strHOSTFQDN = strHOST & strDNSDomain
    strIP = GetIPFromDNS(strHOSTFQDN,strDNSSVR)
    OUTfile.WriteLine strDomain & " " & strHOST & " " & strIP
    'Comment line below to not dump output to screen
    Wscript.Echo strDomain & " " & strHOST & " " & strIP
     objRecordSet.MoveNext
Loop

Function GetIPFromDNS(sFQDN, strDNS)
  Set objWMI=GetObject("WinMgmts://" & strDNS & "\root\microsoftDNS")    
  Set colIP=objWMI.ExecQuery("Select * from MicrosoftDNS_AType where ownerName='" & sFQDN & "'")     
    For Each item In colIP          
        GetIPFromDNS = item.RecordData     
    Next
End Function

Outfile.Close 

相关内容