본문 바로가기
씨샵

[C#] 로컬IP 확인방법

by 케야르 2021. 1. 27.

로컬아이피 확인 방법은 아래와 같습니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
        /// <summary>
        /// 로컬IP를 반환합니다.
        /// </summary>
        /// <returns></returns>
        private string GetLocalIP()
        {
            string myIP = "";
            IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
 
            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    myIP = ip.ToString();
                }
            }
            return myIP;
        }
        #endregion
cs