2
This code retrieves the gateway standard, but I can’t convert the result to string and put on 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...
}
Which error occurs?
– Marco Giovanni
An unhandled Exception of type 'System.Net.Sockets.Socketexception' occurred in System.dll Additional information: There is no support for the attempted operation for the object type to which reference is made
– Ícaro Dantas