티스토리 뷰

반응형

[c#/wpf/unity] 나의 아이피 주소 가져오기 헬퍼구현

 

 public static class NetworkHelper
    {
        public static string GetMyIpAddress()
        {
            var host = Dns.GetHostEntry(Dns.GetHostName());

            foreach (var ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    return ip.ToString();
                }
            }

            throw new Exception("error");
        }

        public static bool IsLocalHost(IPEndPoint ep)
        {
            return ep.Address.ToString().Equals(GetMyIpAddress());
        }

    }

 

#c# #wpf #unity #get ipaddress 

반응형
댓글
반응형