본문 바로가기
Programming/C#

[C#] Gateway 구하기

by 호호호호히히히히 2019. 8. 28.
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);
        }
    }
}

 

 

반응형

'Programming > C#' 카테고리의 다른 글

[C#] SubnetMask 구하기  (0) 2019.08.30
[C#] DNS서버 구하기  (0) 2019.08.29
[C#] 로컬 IP 주소 구하기  (0) 2019.08.27
[C#] 수행시간 구하기  (0) 2018.08.21
[C#/WinForm] 창 크기 조절하기  (0) 2018.08.20

댓글