Tuesday, August 26, 2008

DomainName & Default Gateway : C#

To get the LAN domain name and default gateway address try the below code
Note: don't forget to include the namespace

using System.Net.NetworkInformation;

IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
string intranetDomainName = ipProperties.DomainName;
foreach (NetworkInterface networkCard in NetworkInterface.GetAllNetworkInterfaces())
{
foreach (GatewayIPAddressInformation gatewayAddress in networkCard.GetIPProperties().GatewayAddresses)
{
string defaultGatewayAddress = gatewayAddress.Address.ToString();
}
}

No comments: