One of the SOCK5 Proxy (GCC articles) for your QQ

zhaozj2021-02-16  70

This article uses qq as an object, teach you how to write a SOCK5 PROXY

First, prepare work =========================================================================================================================================================================== The Win32 version of GCC can be downloaded from www.mingw.org, or the GCC itself with DEV-C is also available.

2. Program running environment: You can run under Windows 2000 / XP and Linux, Win9x system has not tried it, I don't know it.

3. How to compile: Use gcc mysock5.c -o mysock5 in WinUX to use GCC MySock5.c -o mySock5.exe -lwsock32 in Win32 to indicate the library related to the Windows Socket, otherwise Will be wrong, compile under Linux.

Second, basic ideas ================================= I don't want me to say more, or immediately enter the topic. Sock5 is a proxy agreement, support TCP and The UDP protocol is also the only supported Proxy type of QQ. For details, please refer to RFC1928.txt.

1. Handshake Process Customer Programs To use Proxy service, first you have to shake hands with Proxy Server, this process is based on TCP / IP protocol.

2. Data transfer QQ is to use UDP to transmit information, so when QQ and SOCK5 Proxy handshake, turn to a UDP Socket, that is, our program first builds a TCP Socket and QQ to shake hands, then To create a UDP Socket to perform data transfer, implement the function of the proxy service.

This is the simplest proxy, only supports one user connection, and you need to exit restart after the connection is aborted.

Third, the program frame =================== first look at the source code MYSOCK5.C

#include #include #include #include

The Socket API provided by WINDOWS and Linux systems is different. They need to declare #ifdef _win32 # include #include # Else # include #include #include #ENDIF

/ / Define a buffer #define bufsz 65535char buf [buffs];

INT Main (int Argc, char ** argv) {// This is the data of Server, including the IP address and port number short tcp_proxy_port = 8888 used as TCP and UDP connections, UDP_PROXY_PORT = 8811; char udp_proxy_ip [] = "127.0. 0.1 "; short cat_udp_port;

/ / Under the Windows system, use WSAStartup () before using the network, // WSA is the meaning of the Windows Socket API, this article uses the Winsock 2.0 version // You can use Winsock_Version in the VC to specify the version, but gcc for Win32 does not define this macro // we need to specify #ifdef _win32 wsadata wsadata; if (WsaStartup (0x0110, & wsadata) {// if (WSAStartup (WSADATA)) {p_ERROR ("WSA Error"); exit 1);} # endif // Start a TCP Socket, use to hold hands with QQ, and record the UDP port number (CLT_UDP_PORT) launch_tcp (CLT_UDP_PORT) launch_tcp used to communicate with us ;._ip, udp_port, & clt_udp_port);

// After the handshake is successful, start a UDP Socket, used as a data transfer, is a part of the Proxy role part of Launch_UDP (UDP_PROXY_PORT, UDP_PROXY_IP, CLT_UDP_UDP_PORT); RETURN 0;}

Fourth, the tool function =================== is the so-called workers, the best, the good procedure, certain, can not lack a good tool function, there is These functions are more convenient for debugging.

1. P_ERROR This is a function that handles error messages, and uses a function in all error information. It is currently using printf () to output it, of course, can also be output to file or simply ignore it. :)

Void p_error (const char * err_msg) {printf ("Err =>% S / N", Err_MSG);

2. Debug_showbin is used to output a piece of data (16)

Void debug_showbin (const char * dbuf, int n, const char * name, const char * end) {INT i; printf ("% s ==>% D Bytes:", Name, N);

For (i = 0; i

Printf ("% s", end);

3. Debug_showip Use IP and Port in SockAddr_in type data

Void Debug_Showip (const struct sockaddr_in * dbuf, const char * name, const char * end) {printf ("[% s ==>% s:% u]% s", name, inet_ntoa (dbuf-> sin_addr), NTOHS (DBUF-> SIN_PORT), END

}

5. Test =================== You can try to compile after downloading the source code, then execute, see if there is any error message :)

Download the source code of this chapter → mysock5_1.c

转载请注明原文地址:https://www.9cbs.com/read-14366.html

New Post(0)