0

Code to get the all ip information from the machine. like ipaddress ip address wireless how to fix this?

I have multiple adapters on my machine. Fetching the ip address with below code is just giving me the array of IP addresses but I need adapter names also corresponding to them so that I can filter them and diplay only particular adapters on my final report.

private void Form1_Load(object sender, EventArgs e)
{
   var host = Dns.GetHostEntry(Dns.GetHostName());
   foreach (var ip in host.AddressList)
   {            
      Console.WriteLine("IP Address = " + ip.ToString());
      label5.Text += (" " + ip);
      label6.Text += (" " + ip);             
   }
}
Rob Goodwin
  • 2,676
  • 2
  • 27
  • 47
  • I have updated the content, please check it again – Santosh Bhaskar Sep 30 '21 at 16:51
  • Does [NetworkInterface.GetAllNetworkInterfaces](https://learn.microsoft.com/en-us/dotnet/api/system.net.networkinformation.networkinterface.getallnetworkinterfaces?view=net-5.0#System_Net_NetworkInformation_NetworkInterface_GetAllNetworkInterfaces) help? – Steeeve Sep 30 '21 at 18:41
  • Does this answer your question? [How to get the IP address of the server on which my C# application is running on?](https://stackoverflow.com/questions/1069103/how-to-get-the-ip-address-of-the-server-on-which-my-c-sharp-application-is-runni) – rustyhu Oct 01 '21 at 15:33
  • we were able to use the NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); and UnicastAddresses[0].Address – Santosh Bhaskar Oct 05 '21 at 12:54
  • I need code to copy the ipaddress and content from the output display. unable to copy – Santosh Bhaskar Oct 05 '21 at 12:58

0 Answers0