BK

我是BK,不断成长,不愿辜负任何对我保有期盼的人...
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

Posted on 2007-10-08 15:11  blue1000  阅读(791)  评论(6编辑  收藏  举报

尊重作者,请保留 www.it55.com 链接字样。

网上有类似的教程,但是是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")