asp.net根据域名查ip C#版

来源:互联网 发布:按键精灵windows插件 编辑:程序博客网 时间:2024/04/29 08:33
asp.net根据域名查ip C#版

网上有类似的教程,但是是asp.net 1.1的版本,这是本人写的,asp.net 2.0支持。


        public string GetIPByDomain(string url)
        {
            if (url.Trim() == string.Empty)
                return "";
            try
            {
                System.Net.IPHostEntry host = System.Net.Dns.GetHostEntry(url);
                return host.AddressList.GetValue(0).ToString();
            }
            catch (Exception e)
            { 
                throw e;
            }
       }

调用方法: GetIPByDomain("www.it55.com")

原创粉丝点击