现在我在做一个东西,想让他在知道ip号后,给个提示:您的IP是:。,是联通的用户,建议您用联通通道下载。
给用户提示采用哪个地址下载,这样一个功能。请各位高手指点一二

解决方案 »

  1.   

    本帖最后由 net_lover 于 2011-09-29 09:58:38 编辑
      

  2.   

    这个IP数据库是可以得到IP号,那怎么判断运营商呢,有算法吗?这个IP数据库我还在下载不知道效果如何。
      

  3.   

    这个ip库是国内比较全的。
    上面的文章你看了没?IPScanner objScan = new IPScanner();//string ip = Request.ServerVariables.Get("REMOTE_ADDR");//自动获取用户IPstring ip = this.TextBox1.Text;objScan.DataPath = Server.MapPath(@"Inc/QQWry.Dat");objScan.IP = ip;string addre = objScan.IPLocation();this.TextBox1.Text = addre;这里的addre就是你的供应商信息
      

  4.   

    文章中的程序有点错误。string pattern = @"(((d{1,2})|(1d{2})|(2[0-4]d)|(25[0-5])).){3}((d{1,2})|(1d{2})|(2[0-4]d)|(25[0-5]))";
    Regex objRe = new Regex(pattern);
    Match objMa = objRe.Match(ip);
    if (!objMa.Success)
    {
      this.errMsg = "IP格式错误";
      return 4;
    }这个地方判断的是错误的,删除这段即可
      

  5.   

    或者改成
    string pattern = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
        "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
        "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
        "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
    Regex objRe = new Regex(pattern);
    Match objMa = objRe.Match(ip);
    if (!objMa.Success)
    {
      this.errMsg = "IP格式错误";
      return 4;
    }
      

  6.   


    string ipAddress = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=58.60.125.97";
                WebRequest request = WebRequest.Create(new Uri(ipAddress));
                WebResponse response = request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string responseStr = string.Empty;
                responseStr= HttpUtility.HtmlDecode(reader.ReadToEnd());
                reader.Dispose();
                responseStr = responseStr.Substring(responseStr.IndexOf("=") + 2);
                responseStr = responseStr.Substring(0, responseStr.Length - 1);
                JavaScriptSerializer jss = new JavaScriptSerializer();
                IpInfo ipInfo=jss.Deserialize<IpInfo>(responseStr);
                ViewBag.Response = ipInfo;
                return View();
    public class IpInfo
        {
           public string ret { get; set; }
           public string start { get; set; }
           public string end { get; set; }
           public string country { get; set; }
           public string province { get; set; }
           public string city { get; set; }
           public string district { get; set; }
           public string isp { get; set; }
           public string type { get; set; }
           public string desc { get; set; }
        }result:
    58.60.124.0
    58.60.125.255
    中国
    广东
    深圳
    南山
    电信