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
  							Next
  						WScript.Echo "    Subnet Mask(s):"
  							For Each strIPSubnet In objNicConfig.IPSubnet
    								WScript.Echo "        " & strIPSubnet
  							Next
					Next



			Else

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


Else


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

  End If

Loop
Wscript.quit (0)

Open in new window

IkelcaAsked:
Who is Participating?
 
gcitronConnect With a Mentor Commented:
This script is working fine.
0
 
IkelcaAuthor Commented:
it does not work well to me...
on many of computers
0
 
RobSampsonCommented:
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.

Regards,

Rob.
0
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.