查看: 108|回复: 0

通过域名获得域名解析的IP地址

[复制链接]

3

主题

0

回帖

0

积分

热心网友

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2010-7-11
发表于 2021-4-8 16:02:00 | 显示全部楼层 |阅读模式
/// <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[0];
                rIP = ip.ToString();
            }
            catch {
                rIP = "请输入正确的域名,或者您的电脑没有联互联网";
            }

            return rIP;
        }

  



来源:https://www.cnblogs.com/anduinlothar/p/14632735.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

圆梦公社,专注于为全球华人提供纯粹技术交流的地方,请勿发布任何政治及违法的言论。如有相关侵权、举报、投诉及建议等,请发 E-mail:dzh188@hotmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部