본문 바로가기
Programming/C#

[C#] 로컬 IP 주소 구하기

by 호호호호히히히히 2019. 8. 27.
728x90
반응형

[C#] 로컬 IP 주소 구하기

 

How to get ip address in C#

 

using System.Net;

private void ShowIP()
{
	IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
    
    string IP4Addr = string.Empty;
    
    foreach (Ipaddress ip in host.AddressList)
    {
    	if (ip.AddressFamily == AddressFamily.InterNetwork)
        {
       		ip4Addr = ip.ToString();
            Console.WriteLine(ip4Addr);
        }
    }
}
반응형

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

[C#] DNS서버 구하기  (0) 2019.08.29
[C#] Gateway 구하기  (0) 2019.08.28
[C#] 수행시간 구하기  (0) 2018.08.21
[C#/WinForm] 창 크기 조절하기  (0) 2018.08.20
[C#] C#이란  (0) 2018.04.19

댓글