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;
            }
  • 相关阅读:
    linux安装源码包报错
    中间文件
    c指针复习
    gcc常用编译选项
    第008课_第1个ARM裸板程序及引申
    开发板熟悉与体验
    裸机开发步骤笔记
    linux进阶命令2
    linux进阶命令1
    vi编辑器的使用
  • 原文地址:https://www.cnblogs.com/hycms/p/3948003.html
Copyright © 2011-2022 走看看