通过域名获得域名解析的IP地址
<div class="cnblogs_Highlighter"><pre class="brush:csharp;gutter:true;">/// <summary>
/// 通过域名获得域名解析的IP地址
/// </summary>
/// <param name="url">网址</param>
/// <returns>返回域名解析的IP地址</returns>
private string GetYuMingIP(string url) {
string rIP = string.Empty;
string p = @"(http|https)://(?<domain>[^(:|/]*)";
Regex reg = new Regex(p, RegexOptions.IgnoreCase);
string ipAddress = url;
if (!ipAddress.Contains("http")) {
ipAddress = "http://" + ipAddress;
}
Match m = reg.Match(ipAddress);
string Result = m.Groups["domain"].Value;//域名地址 如http://wwww.luofenmng.com/index.aspx提取出来的是www.luofenming.com
//以下是获取域名解析的IP地址
try {
IPHostEntry host = Dns.GetHostEntry(Result);
IPAddress ip = host.AddressList;
rIP = ip.ToString();
}
catch {
rIP = "请输入正确的域名,或者您的电脑没有联互联网";
}
return rIP;
}
</pre>
</div>
<p> </p><br><br>
来源:https://www.cnblogs.com/anduinlothar/p/14632735.html
頁:
[1]