Programming/C#

[C#] Gateway 구하기

호호호호히히히히 2019. 8. 28. 11:34
728x90
반응형

[C#] Gateway 구하기

How to get gateway in C#

 

using System.Net.NetworkInformation;

privite void showGateway()
{
	NetworkInterface[] adapters  = NetworkInterface.GetAllNetworkInterfaces();
    
    string gateway = string.Empty;
    
    foreach (NetworkInterface adapter in adapters)
    {
        IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
        GatewayIPAddressInformationCollection addresses = adapterProperties.GatewayAddresses;
        if (addresses.Count >0)
        {
            foreach (GatewayIPAddressInformation address in addresses)
            {
                gateway = address.Address.ToString());
            }
            Console.WriteLine(gateway);
        }
    }
}

 

 

반응형