Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture System Information 2

Status
Not open for further replies.

bwgreen

Programmer
Mar 23, 2006
68
CA
I have been asked to write a simple script to capture the IP information (Address, Gateway, Mask, DNS, WINS and suffixes) and print it out. I can get this information simpy using the ipconfig command - is there an easy way to capture this output then send it to the default printer?

Thanks,

Brian
 
here's the code you need:

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colAdapters = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

n = 1
msg = ""

For Each objAdapter in colAdapters
msg = msg & "Network Adapter " & n & vbcrlf
msg = msg & "=================" & vbcrlf
msg = msg & " Description: " & objAdapter.Description & vbcrlf

msg = msg & " Physical (MAC) address: " & objAdapter.MACAddress & vbcrlf
msg = msg & " Host name: " & objAdapter.DNSHostName & vbcrlf

If Not IsNull(objAdapter.IPAddress) Then
For i = 0 To UBound(objAdapter.IPAddress)
msg = msg & " IP address: " & objAdapter.IPAddress(i) & vbcrlf
Next
End If

If Not IsNull(objAdapter.IPSubnet) Then
For i = 0 To UBound(objAdapter.IPSubnet)
msg = msg & " Subnet: " & objAdapter.IPSubnet(i) & vbcrlf
Next
End If

If Not IsNull(objAdapter.DefaultIPGateway) Then
For i = 0 To UBound(objAdapter.DefaultIPGateway)
msg = msg & " Default gateway: " & _
objAdapter.DefaultIPGateway(i) & vbcrlf
Next
End If


msg = msg & " DNS" & vbcrlf
msg = msg & " ---" & vbcrlf
msg = msg & " DNS servers in search order:"

If Not IsNull(objAdapter.DNSServerSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
msg = msg & " " & objAdapter.DNSServerSearchOrder(i) & vbcrlf
Next
End If

msg = msg & " DNS domain: " & objAdapter.DNSDomain & vbcrlf

If Not IsNull(objAdapter.DNSDomainSuffixSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder)
msg = msg & " DNS suffix search list: " & _
objAdapter.DNSDomainSuffixSearchOrder(i) & vbcrlf
Next
End If


msg = msg & " DHCP" & vbcrlf
msg = msg & " ----" & vbcrlf
msg = msg & " DHCP enabled: " & objAdapter.DHCPEnabled & vbcrlf
msg = msg & " DHCP server: " & objAdapter.DHCPServer & vbcrlf

If Not IsNull(objAdapter.DHCPLeaseObtained) Then
utcLeaseObtained = objAdapter.DHCPLeaseObtained
strLeaseObtained = WMIDateStringToDate(utcLeaseObtained)
Else
strLeaseObtained = ""
End If
msg = msg & " DHCP lease obtained: " & strLeaseObtained & vbcrlf

If Not IsNull(objAdapter.DHCPLeaseExpires) Then
utcLeaseExpires = objAdapter.DHCPLeaseExpires
strLeaseExpires = WMIDateStringToDate(utcLeaseExpires)
Else
strLeaseExpires = ""
End If
msg = msg & " DHCP lease expires: " & strLeaseExpires & vbcrlf


msg = msg & " WINS" & vbcrlf
msg = msg & " ----" & vbcrlf
msg = msg & " Primary WINS server: " & objAdapter.WINSPrimaryServer & vbcrlf
msg = msg & " Secondary WINS server: " & objAdapter.WINSSecondaryServer & vbcrlf


n = n + 1

Next
wscript.echo msg
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
 
Why don't you just use this for displaying the information:
Code:
Set oShell = CreateObject("Wscript.Shell")

Set oExec = oShell.Exec("ipconfig -all")
	Do While Not oExec.StdOut.AtEndOfStream
		line = oExec.StdOut.ReadAll
	Loop
	wscript.echo line
You could easily write this to a file instead of "wscript.echo"; strip out the parts you want by "oExec.StdOut.ReadLine" then put in a few "If" statements for "InStr" and write the specific information to the text file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top