Looking for a simple way to retrieve host name, computer name, and ipv6 using asp or vb6
Is there a simple to u开发者_如何学Pythonse easy way to pull the computer name, host name, and ipv6 ipaddress using vb6, asp, or jQuery? The reason is because its for logging information for security.
VB6 doesn't have a way to do this directly inside the language or the runtime as you would do in .NET, however, Windows has an extensive management interface that can be access through COM. The Windows Management Instrumentation (WMI) is a COM-based interface for doing all sorts of management stuff. COM automation is incredibly simple in VB6.
I would suggest looking at the VBScripts done by the Microsoft Scripting Guys, http://technet.microsoft.com/en-us/scriptcenter/default. It should be a relatively simple extercise to port a VBScript to VB6. Here is the VBScript that does what you want:
http://gallery.technet.microsoft.com/scriptcenter/ff7bc830-a67d-434e-9c77-ebe1ff7d6a4d
I don't have VB6 on this machine to get you a perfect code example right now, however, simply changing the Wscript.Echo calls to Debug.Print you can pretty much run this in VB6.
strcomputer = Inputbox("Name of Computer","Computer IP Query")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
n = 1
For Each objAdapter in colAdapters
Debug.Print "Network Adapter " & n
Debug.Print "================="
Debug.Print " Description: " & objAdapter.Description
Debug.Print " Physical (MAC) address: " & objAdapter.MACAddress
Debug.Print " Host name: " & objAdapter.DNSHostName
If Not IsNull(objAdapter.IPAddress) Then
For i = 0 To UBound(objAdapter.IPAddress)
Debug.Print " IP address: " & objAdapter.IPAddress(i)
Next
End If
If Not IsNull(objAdapter.IPSubnet) Then
For i = 0 To UBound(objAdapter.IPSubnet)
Debug.Print " Subnet: " & objAdapter.IPSubnet(i)
Next
End If
If Not IsNull(objAdapter.DefaultIPGateway) Then
For i = 0 To UBound(objAdapter.DefaultIPGateway)
Debug.Print " Default gateway: " & _
objAdapter.DefaultIPGateway(i)
Next
End If
Debug.Print
Debug.Print " DNS"
Debug.Print " ---"
Debug.Print " DNS servers in search order:"
If Not IsNull(objAdapter.DNSServerSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
Debug.Print " " & objAdapter.DNSServerSearchOrder(i)
Next
End If
Debug.Print " DNS domain: " & objAdapter.DNSDomain
If Not IsNull(objAdapter.DNSDomainSuffixSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder)
Debug.Print " DNS suffix search list: " & _
objAdapter.DNSDomainSuffixSearchOrder(i)
Next
End If
Debug.Print
Debug.Print " DHCP"
Debug.Print " ----"
Debug.Print " DHCP enabled: " & objAdapter.DHCPEnabled
Debug.Print " DHCP server: " & objAdapter.DHCPServer
If Not IsNull(objAdapter.DHCPLeaseObtained) Then
utcLeaseObtained = objAdapter.DHCPLeaseObtained
strLeaseObtained = WMIDateStringToDate(utcLeaseObtained)
Else
strLeaseObtained = ""
End If
Debug.Print " DHCP lease obtained: " & strLeaseObtained
If Not IsNull(objAdapter.DHCPLeaseExpires) Then
utcLeaseExpires = objAdapter.DHCPLeaseExpires
strLeaseExpires = WMIDateStringToDate(utcLeaseExpires)
Else
strLeaseExpires = ""
End If
Debug.Print " DHCP lease expires: " & strLeaseExpires
Debug.Print
Debug.Print " WINS"
Debug.Print " ----"
Debug.Print " Primary WINS server: " & objAdapter.WINSPrimaryServer
Debug.Print " Secondary WINS server: " & objAdapter.WINSSecondaryServer
Debug.Print
n = n + 1
Next
Public Function WMIDateStringToDate(utcDate)
WMIDateStringToDate = CDate(Mid(utcDate, 5, 2) & "/" & _
Mid(utcDate, 7, 2) & "/" & _
Left(utcDate, 4) & " " & _
Mid (utcDate, 9, 2) & ":" & _
Mid(utcDate, 11, 2) & ":" & _
Mid(utcDate, 13, 2))
End Function
精彩评论