社区
网络编程
帖子详情
Socks程序设计
zxyjyzxyjy
2008-06-11 08:56:25
第一次接触利用socks编程,不知服务器和客户端如何编写,与socket编程有啥不同。
...全文
310
23
打赏
收藏
Socks程序设计
第一次接触利用socks编程,不知服务器和客户端如何编写,与socket编程有啥不同。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
23 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
lwd4210
2008-07-29
打赏
举报
回复
UP
haode
2008-07-02
打赏
举报
回复
关注
huntstream
2008-07-02
打赏
举报
回复
up
清歌谁与和
2008-06-30
打赏
举报
回复
mark
zxyjyzxyjy
2008-06-30
打赏
举报
回复
up
zxyjyzxyjy
2008-06-27
打赏
举报
回复
有那位达人,说说把服务器放在PROXY后面和放在公网上,服务器端用SOCKET编程到底有啥不同????
zhkefa
2008-06-14
打赏
举报
回复
关注,我也正想学习这方面的知识,,,
zxyjyzxyjy
2008-06-14
打赏
举报
回复
问14楼的朋友:
作为服务器端,是不是用不用socks,服务器端的程序都是一样的呢?
server放在proxy后面,和server放在公网上,是不一样的.
是怎样的区别,能说详细些吗?
lizhigang34
2008-06-14
打赏
举报
回复
mark
学习
CathySun118
2008-06-14
打赏
举报
回复
http://www.vckbase.com/document/viewdoc/?id=484
cppwin
2008-06-14
打赏
举报
回复
作为服务器端,是不是用不用socks,服务器端的程序都是一样的呢?
server放在proxy后面,和server放在公网上,是不一样的.
yiyefenghun
2008-06-14
打赏
举报
回复
应该是
zxyjyzxyjy
2008-06-13
打赏
举报
回复
非常谢谢scq2099yt!!
作为客户端,我也理解程序该怎么做。
作为服务器端,是不是用不用socks,服务器端的程序都是一样的呢?
captain_x
2008-06-12
打赏
举报
回复
mark
scq2099yt
2008-06-11
打赏
举报
回复
原理和模式基本都一样
僵哥
2008-06-11
打赏
举报
回复
Socks只是一个协议,在普通的socket交互上面添加一重协议信息,用于告诉服务器你需要访问谁,如果需要校验的,就需要发送身份信息(用户名+密码)。
天天睡懒觉的墨鱼
2008-06-11
打赏
举报
回复
mark一下,以后看了!
scq2099yt
2008-06-11
打赏
举报
回复
也可以参考一下链接:
http://community.csdn.net/Expert/topic/3711/3711108.xml?temp=.6380884
http://www.codeguru.com/Cpp/I-N/internet/http/article.php/c6209/
http://www.vckbase.com/document/viewdoc/?id=852
http://www.codeproject.com/KB/IP/httptunneling.aspx
scq2099yt
2008-06-11
打赏
举报
回复
用socks5进行udp发送数据的过程:
你的目的是要和服务器做UDP的数据传送。
步骤:
1,和代理建立tcp联接,(你已经完成)。
2,向代理发送版本的请求信息, 我的实现:
void CCommunicator::SendVer()
{
int datasize = 6;
char tempbuf[6];
tempbuf[0]=5;
tempbuf[1]=4;//标示后面所根的字接数
tempbuf[2]=0;
tempbuf[3]=1;
tempbuf[4]=2;
tempbuf[5]=3;
int senddatalen;
senddatalen=send(m_sock,(char*)tempbuf,6,0);
}
这一步,你已经返回成功,是吗?如果失败,断开建立的tcp联接,如果成功,如果需要用户验证则进行步骤3,否则进行4.
3,如果需要用户验证,则类似:
BOOL CCommunicator::SendUserTest()
{
int usernamelen=0;
int userpasslen=0;
usernamelen=m_strTestUserName.GetLength();
userpasslen=m_strTestUserPass.GetLength();
char tempbuf[100];
tempbuf[0]=5;
tempbuf[1]=usernamelen;//标示后面所根的字接数
strcpy(&tempbuf[2],m_strTestUserName);
tempbuf[2+usernamelen]=userpasslen;
strcpy((char*)&tempbuf [3+usernamelen],m_strTestUserPass);
int senddatalen;
int len;
len=usernamelen+userpasslen+3;
senddatalen=send(m_sock,(char*)tempbuf,len,0);
} 如果失败,断开建立的tcp联接, 如果用户返回成功,步骤4.
4,发送请求的协议类似:
void CCommunicator::SendRequestUDP()
{
int const datasize=10;
BYTE tempbuf[datasize]; tempbuf[0]=5;
tempbuf[1]=3;//标示UDP连接
tempbuf[2]=0;
tempbuf[3]=1;
tempbuf[4]=0;
tempbuf[5]=0;
tempbuf[6]=0;
tempbuf[7]=0;
*((SHORT*)(&(tempbuf[8])))=m_uBindUDPPort; //UDP在客户端绑定的端口,就是你本地机器的做udp数据传送的端口调用
//socket函数后,再调用bind()来邦定一个端口。
char temp;
temp=tempbuf[8];
tempbuf[8]=tempbuf[9];
tempbuf[9]=temp;
int senddatalen=send(m_sock,(char*)tempbuf,datasize,0);
}
如果失败,断开建立的tcp联接,如果返回成功,验证完毕!步骤5
5,真正的数据传送,用代理传送的时候,数据包的前面加上10个字节类似:
void CCommunicator::CopyDataHead(BYTE * ptempbuf)
{
struct in_addr addr;
addr.s_addr=inet_addr(“202.220.33.333”);//这个ip是服务器端的ip
ptempbuf[0]=0;
ptempbuf[1]=0;
ptempbuf[2]=0;
ptempbuf[3]=1;
ptempbuf[4]=(char)addr.S_un.S_un_b.s_b1;
ptempbuf[5]=(char)addr.S_un.S_un_b.s_b2;
ptempbuf[6]=(char)addr.S_un.S_un_b.s_b3;
ptempbuf[7]=(char)addr.S_un.S_un_b.s_b4;
*((SHORT*)(&(ptempbuf[8])))=m_uServerUDPPort;//服务器的端口,就是你最终要发到那个服务器的端口,也就是你的qq服务器。
char temp;
temp=ptempbuf[8];
ptempbuf[8]=ptempbuf[9];
ptempbuf[9]=temp;
}
真正发送的时候类似:
int CCommunicator::SendBufferUDP(LPBYTE lpBuf,int nLen)
{
BYTE tempbuf[1000];
int iHeadData=0;
struct sockaddr_in her;
her.sin_family=AF_INET;
her.sin_addr.s_addr=inet_addr(m_szProxyAddr);//代理服务器
her.sin_port=htons(m_uSocksPort);//发送请求的时候返回的代理服务器端的端口,记住,这是最重要的。
CopyDataHead(tempbuf);
iHeadData=10;
nLen=nLen+10;
int addr_len;
addr_len=sizeof(struct sockaddr);
CopyMemory((char*)&tempbuf[iHeadData],lpBuf,nLen);
int returndatalen=sendto(m_socket,(char *)tempbuf,nLen,0,(struct sockaddr *)&her,addr_len);
}
scq2099yt
2008-06-11
打赏
举报
回复
穿透代理服务器编程
在网络程序设计过程中,我们经常要与各种类型的代理服务器打交道,比如在企业内部网通过代理去访问Internet网上的服务器等等,一般代理服务器支持几种常见的代理协议标准,如Socks4,Socks5,Http代理,其中Socks5需要用户验证,代理相对复杂。我在查阅RFC文档和相关资料后,特总结一些TCP协议穿透代理服务器的程序片断,希望对大家有所帮助。
正文
在网络程序设计过程中,我们经常要与各种类型的代理服务器打交道,比如在企业内部网通过代理去访问Internet网上的服务器等等,一般代理服务器支持几种常见的代理协议标准,如Socks4,Socks5,Http代理,其中Socks5需要用户验证,代理相对复杂。我在查阅RFC文档和相关资料后,特总结一些TCP协议穿透代理服务器的程序片断,希望对大家有所帮助。
//使用到的结构
struct sock4req1
{
char VN;
char CD;
unsigned short Port;
unsigned long IPAddr;
char other[1];
};
struct sock4ans1
{
char VN;
char CD;
};
struct sock5req1
{
char Ver;
char nMethods;
char Methods[255];
};
struct sock5ans1
{
char Ver;
char Method;
};
struct sock5req2
{
char Ver;
char Cmd;
char Rsv;
char Atyp;
char other[1];
};
struct sock5ans2
{
char Ver;
char Rep;
char Rsv;
char Atyp;
char other[1];
};
struct authreq
{
char Ver;
char Ulen;
char Name[255];
char PLen;
char Pass[255];
};
struct authans
{
char Ver;
char Status;
};
//通过Socks4方式代理
if( !ClientSock.Connect( g_ProxyInfo.m_strProxyIP,g_ProxyInfo.m_nProxyPort) )
{
m_sError = _T("不能连接到代理服务器!");
ClientSock.Close();
return FALSE;
}
char buff[100];
memset(buff,0,100);
struct sock4req1 *m_proxyreq;
m_proxyreq = (struct sock4req1 *)buff;
m_proxyreq->VN = 4;
m_proxyreq->CD = 1;
m_proxyreq->Port = ntohs(GetPort());
m_proxyreq->IPAddr = inet_addr(GetServerHostName());
ClientSock.Send(buff,9);
struct sock4ans1 *m_proxyans;
m_proxyans = (struct sock4ans1 *)buff;
memset(buff,0,100);
ClientSock.Receive(buff,100);
if(m_proxyans->VN != 0 || m_proxyans->CD != 90)
{
m_sError = _T("通过代理连接主站不成功!");
ClientSock.Close();
return FALSE;
}
//通过Socks5方式代理
if( !ClientSock.Connect( g_ProxyInfo.m_strProxyIP,g_ProxyInfo.m_nProxyPort) )
{
m_sError = _T("不能连接到代理服务器!");
ClientSock.Close();
return FALSE;
}
char buff[600];
struct sock5req1 *m_proxyreq1;
m_proxyreq1 = (struct sock5req1 *)buff;
m_proxyreq1->Ver = 5;
m_proxyreq1->nMethods = 2;
m_proxyreq1->Methods[0] = 0;
m_proxyreq1->Methods[1] = 2;
ClientSock.Send(buff,4);
struct sock5ans1 *m_proxyans1;
m_proxyans1 = (struct sock5ans1 *)buff;
memset(buff,0,600);
ClientSock.Receive(buff,600);
if(m_proxyans1->Ver != 5 || (m_proxyans1->Method!=0 && m_proxyans1->Method!=2))
{
m_sError = _T("通过代理连接主站不成功!");
ClientSock.Close();
return FALSE;
}
if(m_proxyans1->Method == 2)
{
int nUserLen = strlen(g_ProxyInfo.m_strProxyUser);
int nPassLen = strlen(g_ProxyInfo.m_strProxyPass);
struct authreq *m_authreq;
m_authreq = (struct authreq *)buff;
m_authreq->Ver = 1;
m_authreq->Ulen = nUserLen;
strcpy(m_authreq->Name,g_ProxyInfo.m_strProxyUser);
m_authreq->PLen = nPassLen;
strcpy(m_authreq->Pass,g_ProxyInfo.m_strProxyPass);
ClientSock.Send(buff,513);
struct authans *m_authans;
m_authans = (struct authans *)buff;
memset(buff,0,600);
ClientSock.Receive(buff,600);
if(m_authans->Ver != 1 || m_authans->Status != 0)
{
m_sError = _T("代理服务器用户验证不成功!");
ClientSock.Close();
return FALSE;
}
}
struct sock5req2 *m_proxyreq2;
m_proxyreq2 = (struct sock5req2 *)buff;
m_proxyreq2->Ver = 5;
m_proxyreq2->Cmd = 1;
m_proxyreq2->Rsv = 0;
m_proxyreq2->Atyp = 1;
unsigned long tmpLong = inet_addr(GetServerHostName());
unsigned short port = ntohs(GetPort());
memcpy(m_proxyreq2->other,&tmpLong,4);
memcpy(m_proxyreq2->other+4,&port,2);
ClientSock.Send(buff,sizeof(struct sock5req2)+5);
struct sock5ans2 *m_proxyans2;
memset(buff,0,600);
m_proxyans2 = (struct sock5ans2 *)buff;
ClientSock.Receive(buff,600);
if(m_proxyans2->Ver != 5 || m_proxyans2->Rep != 0)
{
m_sError = _T("通过代理连接主站不成功!");
ClientSock.Close();
return FALSE;
}
//通过HTTP方式代理
if( !ClientSock.Connect( g_ProxyInfo.m_strProxyIP,g_ProxyInfo.m_nProxyPort) )
{
m_sError = _T("不能连接到代理服务器!");
ClientSock.Close();
return FALSE;
}
char buff[600];
sprintf( buff, "%s%s:%d%s","CONNECT ",GetServerHostName(),GetPort()," HTTP/1.1 User-Agent: MyApp/0.1 ");
ClientSock.Send(buff,strlen(buff)); //发送请求
memset(buff,0,600);
ClientSock.Receive(buff,600);
if(strstr(buff, "HTTP/1.0 200 Connection established") == NULL) //连接不成功
{
m_sError = _T("通过代理连接主站不成功!");
ClientSock.Close();
return FALSE;
}
我们一般先与代理服务器连通,然后向代理服务器发送代理验证的用户名和密码(如果需要,如Socks5代理),验证成功后,再向代理服务器发送需要连接的目的地址和端口。以上代码仅用于TCP连接,如果在内部网侦听或通过UDP协议发送信息,可查阅RFC1829等文档资料。
加载更多回复(3)
Socks
Online v3.0 beta1.zip
现在许多的网路聊天软件,如QQ、ICQ、IRC等,提供
Socks
Proxy的功能,但纵然你有HTTP Proxy等其他代理,也不能让这些聊天程序通过代理来连接服务器。现在,你可以使用
Socks
Online这个软件,就可以将HTTP Proxy或...
Tor匿名通信系统的RouterUpdate和
SOCKS
代理设计
Tor系统可在通信中为用户提供匿名服务。为解决匿名通信系统Tor在未连接目录...该方案通过重新设计Tor系统的网络功能,可以使新的Tor系统替换所有使用TCP协议进行基础传输的应用程序,或者这些程序是否支持
SOCKS
代理。
rfc1928:
SOCKS
V5中文版
本备忘录状态 本文档讲述了一种...在这儿所描述的协议框架是为了让使用TCP和UDP的客户/服务器应用程序更方便安全地使用网络防火墙所提供的服 务所设计的。这个协议从概念上来讲是介于应用层和传输层之间的“中介层
micro
socks
:很小的便携式
SOCKS
5服务器,具有非常适度的资源使用
它的设计也很健壮:它通过简单地拒绝新连接来优雅地处理资源耗尽,而不是像当今大多数其他程序那样调用abort()。 另一个优点是易于使用:不需要配置文件,所有操作都可以从命令行完成,甚至不需要任何参数即可...
java开源包4
ftp4j提供多种方式连接到远程FTP服务器包括:通过 TCP/IP直接连接,通过FTP代理、HTTP代理、
SOCKS
4/4a代理和
SOCKS
5代理连接,通过SSL安全连接。 Java的命令行进度条 JCmdLineProgess JCmdLineProgess 是一个 Java ...
网络编程
18,356
社区成员
64,214
社区内容
发帖
与我相关
我的任务
网络编程
VC/MFC 网络编程
复制链接
扫一扫
分享
社区描述
VC/MFC 网络编程
c++
c语言
开发语言
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章