본문 바로가기

.NET/C#

C# IPv4, IPv6

 
string strAddress = "10.10.10.10";
            IPAddress adress = IPAddress.Parse(strAddress);
            if(adress.AddressFamily == AddressFamily.InterNetworkV6) // Check IPv6
            {
                if(adress.IsIPv4MappedToIPv6)
                    //Convert IPv6 to IPv4
                    adress = adress.MapToIPv4();   
            }
            string strMyIP = string.Empty;
            if (adress.AddressFamily == AddressFamily.InterNetwork) // Check IPv4
            {
                strMyIP = adress.ToString();
                if (string.IsNullOrEmpty(strMyIP))
                    return false;
            }
            else
                return false;

 

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

C# Delay 함수  (0) 2013.08.27
C# MSDN 참고  (0) 2012.07.25
C# 교재  (0) 2011.11.04