c# 快速驗證代理IP是否有用

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; //設置代理 
            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();
                    }
                }
            }
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章