分享
 
 
 

使用socks4 socks5 http代理的客户端

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

///定义的结构

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;

unsigned long IPAddr;

unsigned short Port;

// 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;

};

///////////

///////////代码片段

void CTestDlg::OnSocks4()

{

CString m_sError;

ClientSock.Create();

//Socks4代理服务器端口及地址

//if( !ClientSock.Connect( "195.65.215.38",1080) )

if( !ClientSock.Connect( "192.168.123.194",1080) )

{

m_sError = _T("不能连接到代理服务器!");

ClientSock.Close();

MessageBox(m_sError);

return ;

}

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(21);

m_proxyreq->IPAddr = inet_addr("219.201.39.50");

strcpy(m_proxyreq->other , "");

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();

MessageBox(m_sError);

return ;

}

//连接已经建立,发送及接收数据

memset(buff,0,100);

strcpy(buff,"Hello!");

ClientSock.Send(buff,sizeof(buff));

memset(buff,0,100);

ClientSock.Receive(buff,100);

MessageBox(buff);

ClientSock.Close();

}

void CTestDlg::OnSocks5()

{

// TODO: Add your control notification handler code here

//http://my.nbip.net/homepage/nblulei/ttdl/sockdllb.htm

CString m_sError;

ClientSock.Create();

//Socks5代理服务器端口及地址

//if( !ClientSock.Connect("61.238.12.84",12654) )

if( !ClientSock.Connect("192.168.123.194",1080) )

{

m_sError = _T("不能连接到代理服务器!");

ClientSock.Close();

MessageBox(m_sError);

return ;

}

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();

MessageBox(m_sError);

return ;

}

if(m_proxyans1->Method == 2)

{

int nUserLen = strlen("alon");

int nPassLen = strlen("alon");

struct authreq *m_authreq = {0};

m_authreq = (struct authreq *)buff;

m_authreq->Ver = 1;

m_authreq->Ulen = nUserLen;

strcpy(m_authreq->Name,"alon");

m_authreq->PLen = nPassLen;

strcpy(m_authreq->Pass,"alon");

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();

MessageBox(m_sError);

return ;

}

}

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;

m_proxyreq2->IPAddr = inet_addr("219.201.39.50");

m_proxyreq2->Port = ntohs(21);

ClientSock.Send(buff,sizeof(struct sock5req2));

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();

MessageBox(m_sError);

return ;

}

//连接已经建立,发送及接收数据

memset(buff,0,600);

strcpy(buff,"Hello!");

ClientSock.Send(buff,sizeof(buff));

memset(buff,0,600);

ClientSock.Receive(buff,600);

MessageBox(buff);

ClientSock.Close();

}

void CTestDlg::OnHttp()

{

// TODO: Add your control notification handler code here

CString m_sError;

ClientSock.Create();

//if( !ClientSock.Connect("61.145.123.202",3128) )

if( !ClientSock.Connect("211.92.143.19",3128) )

//if( !ClientSock.Connect("WWW.TOM.COM",80) )

{

m_sError = _T("不能连接到代理服务器!");

ClientSock.Close();

MessageBox(m_sError);

return ;

}

char buff[600] = {0};

// sprintf( buff, "%s%s:%d%s","CONNECT ","219.201.39.50",21," HTTP/1.1\r\nUser-Agent: MyApp/0.1\r\n\r\n");

sprintf( buff, "%s%s:%d%s","CONNECT ","219.201.39.50",21," HTTP/1.1\r\nUser-Agent: CERN-LineMode/2.15 libwww/2.17b3\r\n\r\n");

// sprintf( buff, "%s%s:%d%s","CONNECT ","www.tom.com",80," HTTP/1.1\r\nUser-Agent: CERN-LineMode/2.15 libwww/2.17b3\r\n\r\n");

// sprintf( buff, "%s%s","GET ","HTTP://WWW.TOM.COM HTTP/1.1\r\n\r\n");

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 ;

}

/* if( strstr(buff, "Error 403") )

{

//return GoError(PROXYERROR_PROXYDISABLE); //代理服务器拒绝请求

}

if( strstr(buff, "407 Proxy authentication required") ) //需要身份验证

{

//return GoError(PROXYERROR_USERNAMEORPASSWORD); //用户身份校检不成功

}

if( strstr(buff, "Connection refuesed") )

{

//return GoError(PROXYERROR_CONNECTHOSTSERVER); //通过代理连接主站不成功

}

if( strstr(buff, "Access Denied") )

{

//return GoError(PROXYERROR_USERNAMEORPASSWORD); //用户身份校检不成功

}

if(strstr(buff, "Connection refused by Remote Host") )

{

//return GoError(PROXYERROR_CONNECTHOSTSERVER); //通过代理连接主站不成功

}

ClientSock.Close();

*/

//连接已经建立,发送及接收数据

memset(buff,0,600);

strcpy(buff,"Hello!");

ClientSock.Send(buff,sizeof(buff));

memset(buff,0,600);

ClientSock.Receive(buff,600);

MessageBox(buff);

ClientSock.Close();

}

/////////

///另附一些http的请求和返回

发送一:

CONNECT 61.135.158.91:80 HTTP/1.1

User-Agent: MyApp/0.1

发送二:

CONNECT 61.135.158.91:80 HTTP/1.1

User-Agent: CERN-LineMode/2.15 libwww/2.17b3

发送三:

CONNECT 127.0.0.1:2222 HTTP/1.0

User-agent: MyApp/1.0

Proxy-authorization: enter xxxxxx

接收一:

HTTP/1.0 403 Forbidden

Server: Topproxy-2.0/

Mime-Version: 1.0

Date: Thu, 18 Nov 2004 16:37:53 GMT

Content-Type: text/html

Content-Length: 718

Expires: Thu, 18 Nov 2004 16:37:53 GMT

X-Squid-Error: ERR_ACCESS_DENIED 0

X-Cache: MISS fro

接收二:

HTTP/1.0 502 Proxy Error ( SSL port specified is not allowed. )

Via: 1.0 PROXY

Pragma: no-cache

Cache-Control: no-cache

Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

<html>

<head>

<meta http-equiv="Conten"

接收三:

HTTP/1.1 403 Forbidden

Date: Sat, 20 Nov 2004 14:33:13 GMT

Content-Length: 257

Content-Type: text/html

Server: NetCache appliance (NetApp/5.6R1D6)

<HTML>

<HEAD><TITLE>403 Forbidden</TITLE></HEAD>

<BODY>

<H1>Forbidden</H1>

<H4>

You were"

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有