본문 바로가기
개발/C#

C# 로컬IP(서버IP)정보 조회

by 혈중마라농도 2022. 1. 6.
public static string GetLocalIP()
{
    try
    {
        IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
        foreach(IPAddress ip in host.AddressList)
        {
            if(ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                return ip.ToString();
            }
        }
        return string.Empty;
    }
    catch(Exception ex)
    {
        Console.WriteLine(ex.ToString());
    }
    return string.Empty;
}
반응형

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

C# byte to int  (0) 2022.01.11
C# 클라이언트 Browser 정보얻기  (0) 2022.01.07
C# 파일사이즈 Long -> String 변환  (0) 2022.01.06
ASP.net 클라이언트IP 얻기  (0) 2022.01.06
c# 양력 -> 음력 변환  (0) 2021.12.05

댓글