C#获取指定网址的ip

C#获取指定网址的ip

命名空间

using System.Net.NetworkInformation;
using System.Net;

代码

public String GetIP(String website)
{
    
    
    String ipAddress = "";
    Ping p = new Ping();
    try
    {
    
    
        PingReply r = p.Send(website);
        if (r.Status == IPStatus.Success)
        {
    
    
            ipAddress = r.Address.ToString();
        }
    }
    catch (Exception)
    {
    
    
        throw;
    }
    return ipAddress;
}

例子

// 例如返回 59.111.19.33
GetIP("music.163.com");

猜你喜欢

转载自blog.csdn.net/qq_38463737/article/details/121503950