프로그래밍/C#

Get Client IP Address in C#

bluecandyg 2022. 8. 17. 13:44
  • 사용자 IP 주소 가져오기
        #region IP 정보 가져오기
        private string Get_Ip_address()
        {
            var host = Dns.GetHostEntry(Dns.GetHostName());
            string Local_IP = string.Empty;
            foreach (var ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    Local_IP = ip.ToString();
                }
            }

            return Local_IP;
        }
        #endregion