社区
C#
帖子详情
C#使用Socks5代理 浏览网页
yisheng163
2007-07-09 06:15:21
求,C#使用Socks5代理 浏览网页的方法,在百度找了好久,没有满意的答案.
C# 使用http代理 浏览网页,用起来很方便.但Socks5代理 就难找啊.
还有,一般的 Socks5 连接时,都要有帐号密码的.
...全文
1410
16
打赏
收藏
C#使用Socks5代理 浏览网页
求,C#使用Socks5代理 浏览网页的方法,在百度找了好久,没有满意的答案. C# 使用http代理 浏览网页,用起来很方便.但Socks5代理 就难找啊. 还有,一般的 Socks5 连接时,都要有帐号密码的.
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
16 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
ximing214
2009-12-18
打赏
举报
回复
没看明白啊 ..
yisheng163
2007-08-19
打赏
举报
回复
哇 神了 !!!
thoughter
2007-08-17
打赏
举报
回复
直到今天才刚有兴致来尝试完成这个程序-_-b
不知楼主还需不需要
这段程序仅做测试
private void button1_Click(object sender, System.EventArgs e)
{
string proxyHost = "127.0.0.1";//代理的ip和端口
int proxyProt = 9050;
byte[] b;
int rl = 0;
string sr;
textBox1.Text="new SockProxy();";
Application.DoEvents();
SockProxy p = new SockProxy();
// {//如果不需要密码验证,略去这段代码
// p.RequireAuthorize = true;
// p.Username = "jerry";
// p.Password = "456321";
// }
textBox1.Text="p.GetSocket(proxyHost, proxyProt);";
Application.DoEvents();
Socket sRH=null;
try
{
sRH = p.GetSocket(proxyHost, proxyProt);
textBox1.Text="p.ConnectProxyServer";
Application.DoEvents();
p.ConnectProxyServer("www.ip138.com", 80, sRH);
textBox1.Text="sRH.Send(b);";
Application.DoEvents();
SSend("GET / HTTP/1.1\r\n",sRH);
SSend("Connection:close\r\n",sRH);
SSend("Host:www.ip138.com\r\n",sRH);
SSend("User-agent:Mozilla/4.0\r\n",sRH);
SSend("Accept-language:zh-cn\r\n",sRH);
SSend("\r\n",sRH);
b = new byte[1024];
textBox1.Text="sRH.Receive(b);";
Application.DoEvents();
rl = sRH.Receive(b);
sr = Encoding.Default.GetString(b, 0, rl);
textBox1.Text=sr;
while(sr.Length>0)
{
Application.DoEvents();
rl = sRH.Receive(b);
sr = Encoding.Default.GetString(b, 0, rl);
textBox1.Text+=sr;
}
}
catch(Exception ex)
{
textBox1.Text=ex.ToString();
return;
}
}
private void SSend(string str,Socket sRH)
{
byte[] b= Encoding.Default.GetBytes(str);
sRH.Send(b);
}
/// <summary>
/// 使用Socks5代理服务器连接网络
/// </summary>
class SockProxy
{
bool m_RequireAuthorize = false;
string m_user = string.Empty;
string m_pass = string.Empty;
/// <summary>
/// default is false
/// </summary>
public bool RequireAuthorize
{
get { return m_RequireAuthorize; }
set { m_RequireAuthorize = value; }
}
public string Username
{
get { return m_pass; }
set { m_pass = value; }
}
public string Password
{
get { return m_user; }
set { m_user = value; }
}
public bool ConnectProxyServer(string strRemoteHost, int iRemotePort, Socket sProxyServer)
{
//构造Socks5代理服务器第一连接头(无用户名密码)
byte[] bySock5Send = new Byte[10];
bySock5Send[0] = 5;
bySock5Send[1] = 1;
bySock5Send[2] = RequireAuthorize ? (byte)2 : (byte)0;
//发送Socks5代理第一次连接信息
sProxyServer.Send(bySock5Send, 3, SocketFlags.None);
byte[] bySock5Receive = new byte[10];
int iRecCount = sProxyServer.Receive(bySock5Receive, bySock5Receive.Length, SocketFlags.None);
//用户验证
if (bySock5Receive[1] == 2 && !RequireAuthorize)
{
throw new Exception("代理服务器需要进行身份确认。");
}
else if (bySock5Receive[1] == 2)
{
//构造Socks5代理服务器第一连接头(无用户名密码)
byte[] bUser = Encoding.Default.GetBytes(Username);
byte[] bPass = Encoding.Default.GetBytes(Password);
int dl = 3 + bUser.Length + bPass.Length;
bySock5Send = new Byte[dl];
bySock5Send[0] = 5;
bySock5Send[1] = (byte)bUser.Length;
Array.Copy(bUser, 0, bySock5Send, 2, bUser.Length);
bySock5Send[2 + bUser.Length] = (byte)bPass.Length;
Array.Copy(bPass, 0, bySock5Send, 3 + bUser.Length, bPass.Length);
//发送Socks5代理第一次连接信息
sProxyServer.Send(bySock5Send, dl, SocketFlags.None);
bySock5Receive = new byte[100];
iRecCount = sProxyServer.Receive(bySock5Receive, bySock5Receive.Length, SocketFlags.None);
}
if (iRecCount < 2)
{
sProxyServer.Close();
throw new Exception("不能获得代理服务器正确响应。");
}
if (bySock5Receive[0] != 5 || (bySock5Receive[1] != 0 && bySock5Receive[1] != 2))
{
sProxyServer.Close();
throw new Exception("代理服务其返回的响应错误。");
}
if (bySock5Receive[1] == 0)
{
bySock5Send[0] = 5;
bySock5Send[1] = 1;
bySock5Send[2] = 0;
bySock5Send[3] = 1;
IPAddress ipAdd = Dns.Resolve(strRemoteHost).AddressList[0];
string strIp = ipAdd.ToString();
string[] strAryTemp = strIp.Split(new char[] { '.' });
bySock5Send[4] = Convert.ToByte(strAryTemp[0]);
bySock5Send[5] = Convert.ToByte(strAryTemp[1]);
bySock5Send[6] = Convert.ToByte(strAryTemp[2]);
bySock5Send[7] = Convert.ToByte(strAryTemp[3]);
bySock5Send[8] = (byte)(iRemotePort / 256);
bySock5Send[9] = (byte)(iRemotePort % 256);
sProxyServer.Send(bySock5Send, bySock5Send.Length, SocketFlags.None);
iRecCount = sProxyServer.Receive(bySock5Receive, bySock5Receive.Length, SocketFlags.None);
if (bySock5Receive[0] != 5 || bySock5Receive[1] != 0)
{
sProxyServer.Close();
throw new Exception("第二次连接Socks5代理返回数据出错。");
}
return true;
}
else
{
if (bySock5Receive[1] == 2)
throw new Exception("代理服务器需要进行身份确认。");
else
return false;
}
}
public Socket GetSocket(string strIpAdd, int iPort)
{
try
{
IPAddress hostadd = IPAddress.Parse(strIpAdd);//Dns.Resolve(strIpAdd).AddressList[0];
IPEndPoint EPhost = new IPEndPoint(hostadd, iPort);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
s.Connect(EPhost);
return s;
}
catch(Exception e)
{
throw(e);
}
}
hm7921936
2007-08-06
打赏
举报
回复
up
hm7921936
2007-08-03
打赏
举报
回复
up
xuyan9132
2007-07-25
打赏
举报
回复
关注,帮顶
zh-wall-e
2007-07-25
打赏
举报
回复
帮顶。。。
天天学习。。好好向上。。。哈哈
yisheng163
2007-07-25
打赏
举报
回复
找了几个 代理 帮我试试吧.各位.谢谢了.
74.86.40.80 1099
74.86.40.83 1099
帐号 test 密码 2546 有效期6个小时
seulty
2007-07-25
打赏
举报
回复
帮顶,UP~
yisheng163
2007-07-24
打赏
举报
回复
试了好久都不行啊.
yisheng163
2007-07-22
打赏
举报
回复
这个一个socks5代理
IP:121.156.57.130
端口: 9001
用户名: tt
密码: 8888
我现在想要用这个代理 连接 GET www.ip138.com这个地址.取回源代码.
调试好久了.都不行啊.
thoughter
2007-07-18
打赏
举报
回复
http://www.xrss.cn/Info/12098.Html
?
不知道有没有用
卧_槽
2007-07-18
打赏
举报
回复
顶一下
yisheng163
2007-07-17
打赏
举报
回复
加分了 哭 . 55555555555
yisheng163
2007-07-17
打赏
举报
回复
555555555 一个星期了.
yisheng163
2007-07-10
打赏
举报
回复
55555555555555555555
没人顶 也没有人看看.
Socks5
_openlx9_
socks5
_
C#
soks5_
socks5
分享_.net_
用
C#
实现的
SOCKS5
代理
服务器源代码分享给大家
C#
做的
代理
服务器可以
使用
不同的
代理
访问
网页
自己做的一个网络
代理
可以
使用
不同的
代理
访问
网页
Proxy Checker:检查 HTTP、HTTPS、SOCKS4 和
SOCKS5
代理
服务器的程序。-开源
要求:.NET Framework 4.6.1 或更高版本。
Socona.Fiveocks:一个
使用
.NET 5编写的
Socks5
服务器
Socona.Fiveocks:一个
使用
.NET 5编写的
Socks5
服务器
一个基于
C#
的轻巧网络混淆
代理
.zip
一个基于
C#
的轻巧网络混淆
代理
.zip 基于
C#
C#
111,076
社区成员
642,571
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章