I have a problem with a C# Application I am making. I am trying to get all IPs to display in a textbox within a windows form by simply clicking a button. I currently have a base to work with:
private void btnIP_Click(object sender, EventArgs e)
{
NetworkInterface[] ipadapters = NetworkInterface.GetAllNetworkInterfaces();
string iptemplate = @"
Network adapter: {0}
IP: {1}";
string IPText = "";
foreach (NetworkInterface AdapterIP in ipadapters)
{
IPText = IPText + String.Format(iptemplate,
AdapterIP.Name,
AdapterIP = ipadd());
}
txtOutput.Text = IPText;
}
However, I am just not understanding whether I can do this using the
using System.Net.NetworkInformation;
If someone can just explain to me how I can take IPs from there and display it, it would help a lot. I have seen people query DNS to retrieve a hostname etc, but I just want to show all IPv4 and IPv6 addresses for all adapters.
I am just not understanding it. I know that I need to keep the foreach() method but not sure how to build out this code to make it work. Note: I have it working for a descriptions and everything for all adapters but I've created a separate button solely dedicated to IPs.