VPN termux about China.net

Tunneling in C (VPN)

/* all rights reserved */

#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>
#include <termios.h>
#include <termios.h>
#include <fcntl.h>
#include<iostream>
#include<stdio.h> // printf
#include<string.h> // strlen
#include<string> // string
#include<sys/socket.h> // socket
#include<arpa/inet.h> // inet_addr
#include<netdb.h> // hostenta
#include <unistd.h>
#include<iostream>
#include<sys/socket.h> // socket
#include<arpa/inet.h> // inet_addr
using namespace std;
struct sockaddr_in server;
#define BUFLEN 20
int len;
char str[80];
char buff[512];
int numBytesRecv;
unsigned char buf[BUFLEN + 1];
static struct termios tin;
struct con
{
char rec[512];
char c[512];
} conect;
int hostname_to_ip(char *hostname, char *ip)
{
struct hostent *he;
struct in_addr **addr_list;
int i;
if ((he = gethostbyname(hostname)) == NULL)
{
// get the host info
herror("gethostbyname");
return 1;
}
addr_list = (struct in_addr **)he->h_addr_list;
for (i = 0; addr_list[i] != NULL; i++)
{
// Return the first one;
strcpy(ip, inet_ntoa(*addr_list[i]));
return 0;
}
return 1;
}

int main(int argc, char *argv[])
{
char *hostname = argv[1];
char ip[100];
hostname_to_ip(hostname, ip);
printf("%s resolved to %s", hostname, ip);
int sock = socket(AF_INET, SOCK_STREAM, 0);
server.sin_family = AF_INET;
if (argc < 2)
{
printf("\nenter name host\r\nexemple wp.pl, o2.pl, facebook.pl");
scanf("%s", ip);
server.sin_addr.s_addr = inet_addr(ip);
}
else
{
server.sin_addr.s_addr = inet_addr(ip);
}
int port = 80;
if (argc == 3)
{
port = atoi(argv[2]);
}
printf("%s resolved to %s", hostname, ip);
server.sin_port = htons(port);
// conect true/false
connect(sock, (struct sockaddr *)&server, sizeof(server));
FILE *fp;
if ((fp = fopen("test2.html", "w")) == NULL)
{
printf("can't open file to write\n");
exit(1);
};
printf("port is: %d\n", port);
printf("host ip is %s\n", argv[1]);
printf("enter the , exemple:/index.aspx\n");
// get from keyboard page name
scanf("%s", str);

/* tunnelning in c */
sprintf(conect.c,
"CONNECT %s HTTP/1.1 \r\nHost: %s \r\nProxy-Connection: keep-alive \r\nUser-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36\r\n\r\n",
str, ip);
send(sock, conect.c, sizeof(conect.c) + 255, 0);
printf("sending request: %s\n", conect.c);
do
{
numBytesRecv = recv(sock, conect.rec, sizeof(conect.rec) + 255, 0);
printf("%s\n", conect.rec);
fprintf(fp, "%s\n", conect.rec);
fprintf(fp, "%s\n", conect.rec);
memset(&conect.rec, 0, sizeof(conect.rec));
printf("CONNECTED!!\r\n");
}
while (numBytesRecv > 0);
printf("save in test2.html file\n");
fclose(fp);

}

No comments:

Post a Comment