C#之IP地址查看器...

来源:互联网 发布:mysql 更改用户密码 编辑:程序博客网 时间:2024/05/01 21:35
本程序完整源码下载地址:
http://download.csdn.net/download/friendan/4343021

本程序的原理是,用程序打开以下地址,然后从网页源码中提取出IP或域名对应的物理地址即可

http://www.ip138.com/ips1388.asp?ip=www.baidu.cn&action=2

效果截图如下:



主要代码如下:

        //获取IP或域名地址函数        public String getIpAddr(String ip)        {            if (ip.StartsWith("http://"))                ip = ip.Replace("http://", "");            String IP = "http://www.ip138.com/ips1388.asp?ip=";            IP += ip;            IP += "&action=2";            String ipAddr = "";            //获取网页源码            System.Net.WebClient webClient = new System.Net.WebClient();            String strSource = "";            try            {                strSource =webClient.DownloadString(IP);                //this.txbAddr.Text = strSource;            }            catch(System.Net.WebException e)            {                return ipAddr=e.ToString();            }            //提取地址            String regex = @"<li>.+<li>";            ipAddr = System.Text.RegularExpressions.Regex.Match(strSource, regex).ToString();            ipAddr=ipAddr.Replace("<li>本站主数据:", "");            ipAddr = ipAddr.Replace("</li><li>", "");            return ipAddr;        }