Gomathipriya
Gomathipriya

Reputation: 945

doesn't displays the ip address of the system

the following code runs successfully but i couldn't get the ip address of the system.

 ManagementObjectSearcher mos=new ManagementObjectSearcher("select IPAddress,IPEnabled from win32_NetworkAdapterConfiguration where IPEnabled=true");
 ManagementObjectCollection moc=mos.Get();
 foreach(ManagementObject mo in moc)
 {
    Console.WriteLine("Variable = {0},Value = {1}  ",
         mo["IPAddress"],mo["IPEnabled"]);
 }

the above code results as

  " Variable = System.String[]  ,  Value = True"  

can you tell me how to get my system's ip address...?

Upvotes: 1

Views: 181

Answers (1)

MethodMan
MethodMan

Reputation: 18843

If you want to use your original code do the following

ManagementObjectSearcher mos=new ManagementObjectSearcher("select IPAddress,IPEnabled from win32_NetworkAdapterConfiguration where IPEnabled=true");
 ManagementObjectCollection moc=mos.Get();
 foreach(ManagementObject mo in moc)
 {
    Console.WriteLine("Variable = {0},Value = {1}  ",
         (string[])mo["IPAddress"],mo["IPEnabled"]);
 }

if you debug the answer you will see that when you place the mouse outside on the '(' here on this line (string[])mo["IPAddress"],mo["IPEnabled"]) you will see IP Address and a Mac Address

Upvotes: 2

Related Questions