码上来了?
命名空间:
using System.Net;
using System.Text;
/// <summary>
/// 验证IP地址
/// </summary>
/// <param name="str">Ip地址</param>
/// <param name="port">端口号</param>
public static void yanzhen(string str, int port)
{
try
{
WebProxy proxyObject = new WebProxy(str, port);//str为IP地址 port为端口号
HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://www.ip138.com/");
Req.Proxy = proxyObject; //设置代理
Req.Timeout = 30000;
HttpWebResponse Resp = (HttpWebResponse)Req.GetResponse();
string OkStr = "";
Encoding code = Encoding.GetEncoding("UTF-8");
using (StreamReader sr = new StreamReader(Resp.GetResponseStream(), code))
{
if (sr != null)
{
Console.WriteLine(string.Format("验证成功:IP:{0}\t端口:{1}",str,port));
}
}
}
catch(Exception ex)
{
delete(str);
}
}