get distinguished IP thru wmi

im trying to get IP thru wmi in c#
and here is the sample vbs i found

this code shows info from same NIC multiple times

does anyone know why?
and how to fix it ?? so i can have an idea what to do in c#
On Error Resume Next

Dim objWMIService
Dim colFiles
Dim objTextfile
Dim objFSO
Dim strcomputer
Dim sLogFile
set oLogOutput = nothing
Const HKEY_LOCAL_MACHINE = &H80000002

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objTextFile = objFSO.OpenTextFile("serverList.txt",1)

Do Until objTextFile.AtEndOfStream
strcomputer = objTextFile.Readline

' Ping remote computer. If inaccessible, display error message.

  Set objShell = CreateObject("WScript.Shell")
  Set objScriptExec = objShell.Exec("ping -n 2 -w 1000 " & strcomputer)
  strPingResults = LCase(objScriptExec.StdOut.ReadAll)

If InStr(strPingResults, "reply from") Then
 WScript.Echo VbCrLf & "Host Name: " & strcomputer
    Set objWMIService = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")

			If Err = 0 Then

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

				WScript.Echo VbCrLf & "Computer Name: " & strcomputer
				WScript.Echo " IP Addresses & Subnet Masks"

					For Each objNicConfig In colNicConfigs

  						WScript.Echo VbCrLf & "  Network Adapter " & objNicConfig.Index
  						WScript.Echo "    " & objNicConfig.Description & VbCrLf 
 						 WScript.Echo "    IP Address(es):"
  							For Each strIPAddress In objNicConfig.IPAddress
    								WScript.Echo "        " & strIPAddress
  						WScript.Echo "    Subnet Mask(s):"
  							For Each strIPSubnet In objNicConfig.IPSubnet
    								WScript.Echo "        " & strIPSubnet


				Wscript.Echo "Error: Unable to connect to WMI." & VbCrLf & _
       				"Error Number: " & Err.Number & VbCrLf & _
       				"Error Source: " & Err.Source & VbCrLf & _
       				"Error Description: " & Err.Description
   			End If


	WScript.Echo VbCrLf & "Host Name: " & strcomputer & VbCrLf & _
     "  Unable to connect."

  End If

Wscript.quit (0)

Open in new window

Who is Participating?
gcitronConnect With a Mentor Commented:
This script is working fine.
IkelcaAuthor Commented:
it does not work well to me...
on many of computers
Can you comment out On Error Resume Next and see if any errors occur with the script. Also, please let us know what is incorrect about your output.


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.