c# 使用HttpWebRequest,HttpWebResponse 快速验证代理IP是否有用

来源:互联网 发布:阿里云ss 端口 编辑:程序博客网 时间:2024/06/06 08:39

我们可以使用HttpWebRequest,HttpWebResponse 来代理验证,谢谢大家评论指导!
呵呵,是不是很简单啊,其实这段代码改一下还可以做采集器,小偷等程序!我不说了大家自己看
 public void yanzhen(string str, int port)
        {
            WebProxy proxyObject = new WebProxy(str, port);//str为IP地址 port为端口号
            HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://www.whatismyip.com.tw/");
            Req.Proxy = proxyObject; //设置代理
            //转载请标明来自 问题解决园http://wenti.cnblogs.com/
            //文章地址
            HttpWebResponse Resp = (HttpWebResponse)Req.GetResponse();
            string str = "";
            string OkStr = "";
            Encoding code = Encoding.GetEncoding("UTF-8");
            using (StreamReader sr = new StreamReader(Resp.GetResponseStream(), code))
            {
                if (sr != null)
                {
                    try
                    {
                        str = sr.ReadToEnd();
                        StringSub.substr(str, "<h2>", "</h2>", 0);
                        str = str.Substring(str.IndexOf(start) + start.Length);
                        OkStr = str.Substring(0, str.IndexOf(last));
                        MessageBox.Show("验证成功!显示IP为" + OkStr);
                    }
                    catch
                    {
                        MessageBox.Show("文件读取失败!");
                    }
                    finally
                    {
                        sr.Close();
                    }
                }
            }
        }


 

原创粉丝点击