Computer Inventory Script-Grabs IPV6 IP address, not IPV4

Script does everything I need it to do except grabbing the wrong IP ad

Page 1 of 1

1 Replies - 5582 Views - Last Post: 21 May 2009 - 09:38 AM Rate Topic: -----

#1 meechp123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-May 09

Computer Inventory Script-Grabs IPV6 IP address, not IPV4

Posted 21 May 2009 - 07:59 AM

Hello all:

I'm completely new here and I'm hoping someone can help me out.

This script will do everything I need it to do (it grabs computer model, serial, express, Mac Address and IP address) but, it only grabs IPV6 addresses and not the IPV4 address...

Can someone help me out? I'm new to VB and been lost for days! I need to get this done! Please copy and paste into Notepad to test.

'strComputer = InputBox ("Enter your hostname")
 
		Dim WSHShell
		Dim objNTInfo
		Dim GetComputerName
 
		Set objNTInfo = CreateObject("WinNTSystemInfo")
		strComputer = lcase(objNTInfo.ComputerName)
 
strMyEmailAddr = InputBox("This script grabs your computer's serial, express code and model number. Please enter in your email address")
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
 
For Each objItem in colItems
strSerial = objItem.SerialNumber
Next
 
 
Function model(strComputer)
'Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
Set colAdapters = objWMIService.ExecQuery _
	("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") 
 
For Each objItem in colItems
model = objItem.Model 
next
End Function
 
Function Base2Base(InputNumber,InputBase,OutputBase)
Dim J, K, DecimalValue, X, MaxBase, InputNumberLength
Dim NumericBaseData, OutputValue
NumericBaseData = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MaxBase = Len(NumericBaseData)
if (InputBase > MaxBase) OR (OutputBase > MaxBase) then
Base2Base = "N/A"
Exit Function
end if
'Convert InputNumber to Base 10
InputNumberLength = Len(InputNumber)
DecimalValue = 0
for J = 1 to InputNumberLength
for K = 1 to InputBase
if mid(InputNumber, J, 1) = mid(NumericBaseData, K, 1) then
DecimalValue = DecimalValue+int((K-1)*(InputBase^(InputNumberLength-J))+.5)
end if
next
next
'Convert the Base 10 value (DecimalValue) to the desired output base
OutputValue = ""
while DecimalValue > 0
X = int(((DecimalValue/OutputBase)-int(DecimalValue/OutputBase))*OutputBase+1.5)
OutputValue = mid(NumericBaseData, X, 1)+OutputValue
DecimalValue = int(DecimalValue/OutputBase)
Wend
Base2Base = OutputValue
Exit Function
End Function
 
' Get IP and MAC Address
 
strComputer = "."
 
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
 
   strMACAddress = objAdapter.MACAddress
 
   If Not IsNull(objAdapter.IPAddress) Then
	  For i = 0 To UBound(objAdapter.IPAddress)
		 objValue = objAdapter.IPAddress(i)
	  Next
   End If
 
Next 
 
 
'==Message boxes.
 
WScript.Echo "Your Serial: " & strSerial
Wscript.Echo "Express code: " & Base2Base(strSerial, 36, 10)
WScript.Echo "Model:" &  model(strComputer)
WScript.Echo "IP Address:" &  objValue
WScript.Echo "MAC Address:" &  strMACAddress
 
MsgBox("Thank You")
 
 
'==Email
 
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Inventory Info"
objMessage.From = strMyEmailAddr
objMessage.To = "you@email.com"
objMessage.TextBody = "Your Serial: " & strSerial & vbCrLf & "Express Code: " & Base2Base(strSerial, 36, 10) &  vbCrLf & "Model:"  & model(strComputer)& vbCrLf & "IP Address:" & objValue & vbCrLf & "MAC Address:" & strMACAddress
 
 
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
 
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
 
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com"
 
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
 
objMessage.Configuration.Fields.Update
 
'==End remote SMTP server configuration section==
 
objMessage.Send


Is This A Good Question/Topic? 0
  • +

Replies To: Computer Inventory Script-Grabs IPV6 IP address, not IPV4

#2 meechp123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-May 09

Re: Computer Inventory Script-Grabs IPV6 IP address, not IPV4

Posted 21 May 2009 - 09:38 AM

Ok,

Got it working!

This code is helpful for anyone who needs to take inventory of computers and users. It will grab the model number, serial number, express code, Mac Address and IP Address. Then, it will email the results to you.

Save the file as "Something.vbs "

'strComputer = InputBox ("Enter your hostname")
 
		Dim WSHShell
		Dim objNTInfo
		Dim GetComputerName
 
		Set objNTInfo = CreateObject("WinNTSystemInfo")
		strComputer = lcase(objNTInfo.ComputerName)
 
strMyEmailAddr = InputBox("This script grabs your computer's serial, express code and model number. Please enter in your email address")
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
 
For Each objItem in colItems
strSerial = objItem.SerialNumber
Next
 
 
Function model(strComputer)
'Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
Set colAdapters = objWMIService.ExecQuery _
	("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") 
 
For Each objItem in colItems
model = objItem.Model 
next
End Function
 
Function Base2Base(InputNumber,InputBase,OutputBase)
Dim J, K, DecimalValue, X, MaxBase, InputNumberLength
Dim NumericBaseData, OutputValue
NumericBaseData = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MaxBase = Len(NumericBaseData)
if (InputBase > MaxBase) OR (OutputBase > MaxBase) then
Base2Base = "N/A"
Exit Function
end if
'Convert InputNumber to Base 10
InputNumberLength = Len(InputNumber)
DecimalValue = 0
for J = 1 to InputNumberLength
for K = 1 to InputBase
if mid(InputNumber, J, 1) = mid(NumericBaseData, K, 1) then
DecimalValue = DecimalValue+int((K-1)*(InputBase^(InputNumberLength-J))+.5)
end if
next
next
'Convert the Base 10 value (DecimalValue) to the desired output base
OutputValue = ""
while DecimalValue > 0
X = int(((DecimalValue/OutputBase)-int(DecimalValue/OutputBase))*OutputBase+1.5)
OutputValue = mid(NumericBaseData, X, 1)+OutputValue
DecimalValue = int(DecimalValue/OutputBase)
Wend
Base2Base = OutputValue
Exit Function
End Function
 
' Get IP and MAC Address
 
strComputer = "."
 
Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Set colAdapters = objWMIService.ExecQuery _
	("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
n = 1
 
ipcount = 0
For Each objAdapter in colAdapters
 
   strMACAddress = objAdapter.MACAddress
	
   If Not IsNull(objAdapter.IPAddress) Then
	  For i = 0 To UBound(objAdapter.IPAddress)
		 ReDim Preserve ipAddys(ipcount)
		 ipAddys(ipcount) = objAdapter.IPAddress(i)
		 ipcount = ipcount + 1
	  Next
   End If
 

 
 
Next 
 
 
'==Message boxes.
 
WScript.Echo "Your Serial: " & strSerial
Wscript.Echo "Express code: " & Base2Base(strSerial, 36, 10)
WScript.Echo "Model:" &  model(strComputer)
For i = 0 To ipcount-1
  WScript.Echo "IP Address:" &  ipAddys(i)
Next

WScript.Echo "MAC Address:" &  strMACAddress
 
MsgBox("Thank You")
 
 
'==Email
 
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Inventory Info"
objMessage.From = strMyEmailAddr
objMessage.To = "yourEmail@email.com"
objMessage.TextBody = "Your Serial: " & strSerial & vbCrLf & "Express Code: " & Base2Base(strSerial, 36, 10) &  vbCrLf & "Model:"  & model(strComputer)& vbCrLf & "IP Address:" & ipAddys(0) & vbCrLf & "MAC Address:" & strMACAddress
 
 
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
 
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
 
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.emailServer.com"
 
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
 
objMessage.Configuration.Fields.Update
 
'==End remote SMTP server configuration section==
 
objMessage.Send  

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1