2015年9月10日 星期四

C# 取得自己的 IP

Code


IPAddress GetIP()
{
    foreach (IPAddress ip in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
        if (ip.AddressFamily == AddressFamily.InterNetwork)
            return ip;
    return null;
}


Reference


How to get the IP address of the server on which my C# application is running on?

沒有留言:

張貼留言