Frutarom IT
asked on
Local DNS Servers with C#
I am trying to find my local DNS Servers in C# and apply them to a string that uses Environment.NewLine to use a new line for the start of a new Server.
I have this from StackOverflow. I just can't seem how to figure out a way to apply it to a string with a NewLine at each new Server.
public static IPAddress GetDnsAddress()
{
NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface networkInterface in networkInterfaces)
{
if (networkInterface.OperationalStatus == OperationalStatus.Up)
{
IPInterfaceProperties ipProperties = networkInterface.GetIPProperties();
IPAddressCollection dnsAddresses = ipProperties.DnsAddresses;
foreach (IPAddress dnsAdress in dnsAddresses)
{
return dnsAdress;
}
}
}
throw new InvalidOperationException("Unable to find DNS Address");
}
I have this from StackOverflow. I just can't seem how to figure out a way to apply it to a string with a NewLine at each new Server.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
In the end I want something like
Label1.Text += DnsServer + Environment.NewLine;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
.... Console.WriteLine(someStri ng); is equivalent to Label1.Text += someString;
ASKER
This will do the same, but only able to output to the console. This does not work for the same way, and my alterations just give me errors.