zoukankan      html  css  js  c++  java
  • 【原创】验证代理IP是否有用

            /// <summary>
            /// 验证代理IP是否有用
            /// </summary>
            /// <param name="ip">IP地址</param>
            /// <param name="port">端口号</param>
            /// <returns>可用返回true</returns>
            static bool IsEnabled(string ip, int port)
            {
                try
                {
                    HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://www.whatismyip.com.tw/");
                    WebProxy proxyObject = new WebProxy(ip, port);//IP地址,端口号
                    Req.Proxy = proxyObject; //设置代理
                    Req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/31.0";
                    HttpWebResponse Resp = (HttpWebResponse)Req.GetResponse();
                    Encoding code = Encoding.GetEncoding("UTF-8");
                    using (StreamReader sr = new StreamReader(Resp.GetResponseStream(), code))
                    {
                        if (sr != null)
                        {
    
                            string strHtml = sr.ReadToEnd();
    
                            MatchCollection mc = Regex.Matches(strHtml, "<h2>(?<text>.*?)</h2>", RegexOptions.IgnoreCase);
                            if (mc.Count > 0)
                            {
                                GroupCollection gc = mc[0].Groups;
                                if (ip == gc["text"].Value)
                                {
                                    return true;
                                }
                            }
                        }
                    }
                }
                catch
                {
                    return false;
                }
                return false;
            }
  • 相关阅读:
    注册审核
    静态表单验证
    多条件查询
    0623TP框架联系
    0618框架 增删改练习
    php框架 数据添加
    0616框架查询
    0614空操作方法 空控制器 跨控制器调用 命名空间
    php 0613框架基础
    php查询
  • 原文地址:https://www.cnblogs.com/hycms/p/3948003.html
Copyright © 2011-2022 走看看