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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gcitronCommented:
This script is working fine.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.