/*
* socksapp - 通过SOCKS代理向pop.mail.yahoo.com这个服务器发送一个用户登录请求,并取得
* 该POP3服务器的响应。该程序演示了如何使得自己的网络程序通透过SOCKS防火墙而向远程服务
* 器通信。
* 要求运行socksapp的主机的DNS设置能解释得通pop.mail.yahoo.com这个服务器地址。
* 128.11.68.63 - 要不,你就直接使用这个IP地址,这是我PING出来的IP。
*/
//作者:冬雪
//2001-1-31
#ifdef WIN32
#include <winsock2.h>
#endif
#include <stdio.h>
#include "ssocks.h"
#include "sdns.h"
#define SOCKS_PROXY "192.168.100.2"
#define SOCKS_PROXY_PORT 1080
#define TARGET_POP3SERVER "128.11.68.63" //POP.MAIL.YAHOO.COM
int Usage(char** argv)
{
printf("$@ Usage:\n\
%s socksproxyip socksproxyport pop3server youraccount yourpassword\n\
socksproxyip - socks proxy 's ip address\n\
socksproxyport - socks proxy's port,1080 default\n\
pop3server - pop3 server \n\
youraccount - Your account on that pop3server\n\
yourpassword - Your password of that account \n",
argv[0]);
return TRUE;
}
int main(int argc, char* argv[])
{
//0.初始化SOCKET
printf("* SocksApp ver 1.0 \n* Powered by Billy.(dxshi@yahoo.com)\n\n");
if(argc<6)
{
Usage(argv);
return 0;
}
#ifdef WIN32
WSADATA wsaData;
if (WSAStartup(0x0101, &wsaData))
{
printf("Error:socket init failed!\n");
return FALSE;
}
#endif
//1.创建客户端SOCKET
int clisock=socket(AF_INET,SOCK_STREAM,0);
if(clisock==INVALID_SOCKET)
{
printf("Create socket failed!\n");
return FALSE;
}
//2.向SOCK5服务器连接
struct sockaddr_in saproxy;
memset(&saproxy, 0, sizeof(saproxy));
saproxy.sin_family = AF_INET;
saproxy.sin_addr.s_addr = inet_addr(argv[1]);//这是我的SOCKS服务器
saproxy.sin_port = htons(atoi(argv[2]));
if(connect(clisock, (struct sockaddr*)&saproxy, sizeof(struct sockaddr)) != 0)
{
printf("Connect to socks proxy: %s port %d failed!\n",SOCKS_PROXY,SOCKS_PROXY_PORT);
return FALSE;
}
else
{
printf("* Connect to socks proxy: %s port %d success!\n",SOCKS_PROXY,SOCKS_PROXY_PORT);
}
//3.向SOCK5服务器认证
//源文:
/*
The client connects to the server, and sends a version
identifier/method selection message:
+----+----------+----------+
|VER | NMETHODS | METHODS |
+----+----------+----------+
| 1 | 1 | 1 to 255 |
+----+----------+----------+
The VER field is set to X'05' for this version of the protocol. The
NMETHODS field contains the number of method identifier octets that
appear in the METHODS field.
*/
CSSocks socks;
if(!socks.Auth(clisock,AUTH_NO)) //用于SOCK5服务器不需要认证的情况!
{
printf("Auth failed!\n");
return FALSE;
}
//4.与真正的服务器建立连接
struct sockaddr_in tarsocksrv;
memset(&tarsocksrv,0,sizeof(tarsocksrv));
//tarsocksrv.sin_addr.s_addr = inet_addr(argv[3]);
CSDns dns;
tarsocksrv.sin_addr = dns.GetIpByHost(argv[3]);
tarsocksrv.sin_port = htons(110);
tarsocksrv.sin_family = AF_INET;
if(!socks.Connect(clisock,tarsocksrv))//yahoo.
{
printf("Connect to yahoo pop3 server failed!\n");
return FALSE;
}
else
{
printf("* Connect to pop3 server %s : %d success!\n",
TARGET_POP3SERVER,110);
}
//到此,便使原来的程序支持SOCKS代理!
//下面你就可以利用clisock与pop.mail.yahoo.com 进行通信了!
//比如:进行POP3用户名协商
char szRecv[128];
memset(szRecv,0,128);
recv(clisock,szRecv,127,0);
printf("* WELCOME <== %s\n",szRecv);
char szPopProto[128];
memset(szPopProto,0,128);
sprintf(szPopProto,"USER %s\r\n",argv[4]);
int nSend=send(clisock,szPopProto,strlen(szPopProto),0);
printf("* COMMAND ==>: %s\n",szPopProto);
//char szRecv[128];
memset(szRecv,0,128);
recv(clisock,szRecv,127,0);
printf("* RESPONSE <== %s",szRecv);
memset(szPopProto,0,128);
sprintf(szPopProto,"PASS %s\r\n",argv[5]);
nSend=send(clisock,szPopProto,strlen(szPopProto),0);
printf("* COMMAND ==>: %s\n",szPopProto);
memset(szRecv,0,128);
recv(clisock,szRecv,127,0);
printf("* RESPONSE <== %s",szRecv);
closesocket(clisock);
shutdown(clisock,SD_BOTH);
return 0;
}
programxh
- 粉丝: 17
- 资源: 1万+
最新资源
- linux常用命令大全.txt
- linux常用命令大全.txt
- linux常用命令大全.txt
- logd/logcat源码
- 排序算法中插入排序C++实现及其特性
- 土地出让数据集(2000-2022.12)(104.8W+ 记录,48特征)CSV
- MFC如何修改多文档视图的标签
- 无人机路径规划中基于DDPG算法的MATLAB实现与信噪比优化
- 配电网电压与无功协调优化 以最小化运行成本(包含开关动作成本、功率损耗成本以及设备运行成本)和电压偏差为目标函数,考虑分布式电源的接入,采用线性化和二次松弛方法,将非凸模型转化为二阶锥规划模型,通过优
- MATLAB轴承动力学代码(正常、外圈故障、内圈故障、滚动体故障),根据滚动轴承故障机理建模(含数学方程建立和公式推导)并在MATLAB中采用ODE45进行数值计算 可模拟不同轴承故障类型,输出时域
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈