This code gets the default gateway , but I can not convert the result to string and put it in a label
.
public static IPAddress GetDefaultGateway()
{
var card = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault();
if(card == null) return null;
var address = card.GetIPProperties().GatewayAddresses.FirstOrDefault();
return address.Address;
}
I'm trying like this:
IPAddress gatway;
gatway = GetDefaultGateway();
if(gatway != null)
{
label8.Text = gatway.Address.ToString(); //Aqui da erro...
}