/*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;
/*telnet*/
#define IAC 255
#define CMD 0xff
#define DONT 0xfe
#define DO 0xfd
#define WONT 0xfc
#define WILL 0xfb
#define SB 0xfa
#define GA 0xf9
#define EL 0xf8
#define EC 0xf7
#define AYT 0xf6
#define AO 0xf5
#define IP 0xf4
#define BREAK 0xf3
#define SYNCH 0xf2
#define NOP 0xf1
#define SE 0xf0
#define EOR 0xef
#define ABORT 0xee
#define SUSP 0xed
#define xEOF 0xec
/*ftp*/
#define PRELIM 1
#define COMPLETE 2
#define CONTINUE 3
#define TRANSIENT 4
#define ERROR 5
#define RRQ 01
#define WRQ 02
#define DATA 03
#define ACK 04
#define REC_ESC '\377'
#define REC_EOR '\001'
#define REC_EOF '\002'
#define BLK_EOR 0x80
#define BLK_EOF 0x40
#define BLK_ERRORS 0x20
#define BLK_RESTART 0x10
#define BUFLEN 20
int len;
unsigned char buf[BUFLEN + 1];
static struct termios tin;
char *resolve_hostname(char *hostname) {
struct hostent *he;
struct in_addr **addr_list;
printf("Resolving hostname: %s\n", hostname);
if ((he = gethostbyname(hostname)) == NULL) {
herror("gethostbyname");
return NULL;
}
addr_list = (struct in_addr **)he->h_addr_list;
if (addr_list == NULL) {
return NULL;
}
printf("Resolved IP: %s\n", inet_ntoa(*addr_list[0]));
return inet_ntoa(*addr_list[0]);
}
/*
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;
}
*/
char *heartbled(int sock,char*msg){
char buffer[512]=("GET / HTTP/1.1\r\n\r\n");
// sprintf(msg,"GET / HTTP/1.1\r\n\r\n");
char rectv[512];
char*heart=(char*)malloc(30);
char*blead=(char*)malloc(20);
char*error=(char*)malloc(10);
send(sock, buffer, strlen(buffer) ,0);
recv(sock, heart, strlen (buffer)+1500 , 0);
printf("%s\n\n",heart);
free(heart);
send(sock, buffer, strlen(buffer) ,0);
recv(sock, blead, strlen (buffer)+1500 , 0);
printf("%s\n\n",blead);
free(blead);
send(sock, buffer, strlen(buffer) ,0);
recv(sock, error, strlen (buffer)+1500 , 0);
printf("%s",error);
free(error);
return error;
}
int main(int argc, char *argv[])
{
char *ip_address = resolve_hostname(argv[1]);
int nread; /* return from read() */
int nready;
int maxfd;
char buffer[512]=("GET / HTTP/1.1\r\n\r\n");
//ip= hostname_to_ip(hostname);
printf(" resolved to %s" , ip_address);
int sock = socket(AF_INET, SOCK_STREAM, 0);
server.sin_family = AF_INET;
if (argc < 2 ) {
server.sin_addr.s_addr = inet_addr("185.60.216.35");
}
else{
server.sin_addr.s_addr = inet_addr(ip_address);
}
int port = 80;
if (argc == 3) {
port = atoi(argv[2]); }
if (argc == 4)
{
}
printf("%s resolved to %s" , argv[1] , ip_address);
server.sin_port = htons(port);
connect(sock, (struct sockaddr *)&server, sizeof(server));
struct timeval ts;
ts.tv_sec = 1; // 1 second
ts.tv_usec = 0;
ssize_t numBytesRecv = 10;
char replyMessage[520];
char *replyMessage2[5200];
FILE *fp;
if ((fp=fopen("test2.html", "w"))==NULL) {
printf ("can't open file to write\n");
exit(1); };
/// ######################## ///
/*facebook*/
//dlugi.info 94.152.142.227
printf("port is: %d\n", port);
printf("host ip is %s\n", argv[1]);
printf("enter the , exemple:/index.aspx\n");
if (port==80){;
do
{
heartbled(sock,"GET / HTTP/1.1\r\n\r\n");
numBytesRecv = recv(sock, replyMessage, strlen (replyMessage)+255, 0);
printf("%s\n", replyMessage);
fprintf (fp, "%s\n", replyMessage);
memset(&replyMessage, 0, sizeof(replyMessage));
} while (numBytesRecv>0);
}
else {
while(1){
fd_set fds;
/* Set up polling. */
FD_ZERO(&fds);
if (sock != 0)
FD_SET(sock, &fds);
FD_SET(0, &fds);
// wait for data
int nready = select(sock + 1, &fds, (fd_set *) 0, (fd_set *) 0, &ts);
if (nready < 0) {
perror("select. Error");
return 1;
}
else if (nready == 0) {
ts.tv_sec = 1; // 1 second
ts.tv_usec = 0;
}
else if (sock != 0 && FD_ISSET(sock, &fds)) {
// start by reading a single byte
int rv;
if ((rv = recv(sock , buf , 1 , 0)) < 0){
return 1;}
else if (rv == 0) {
printf("Connection closed by the remote end\n\r");
return 0;
}
if (buf[0] == CMD) {
// read 2 more bytes
len = recv(sock , buf + 1 , 2 , 0);
if (len < 0){
return 1;}
else if (len == 0) {
printf("Connection closed by the remote end\n\r");
return 0;
}
//negotiate(sock, buf, 3);
}
else {
len = 1;
buf[len] = '\0';
printf("%s", buf);
fprintf(fp,"%s", buf);
fflush(0);
// tcflush(sock, 0);
}
}
else if (FD_ISSET(0, &fds)) {
buf[0] = getc(stdin); //fgets(buf, 1, stdin);
if (send(sock, buf, 1, 0) < 0)
return 1;
if (buf[0] == '\n') // with the terminal in raw mode we need to force a LF
putchar('\r');
}
}
}
printf("save co test2.html file\n");
fclose (fp);
}
#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;
/*telnet*/
#define IAC 255
#define CMD 0xff
#define DONT 0xfe
#define DO 0xfd
#define WONT 0xfc
#define WILL 0xfb
#define SB 0xfa
#define GA 0xf9
#define EL 0xf8
#define EC 0xf7
#define AYT 0xf6
#define AO 0xf5
#define IP 0xf4
#define BREAK 0xf3
#define SYNCH 0xf2
#define NOP 0xf1
#define SE 0xf0
#define EOR 0xef
#define ABORT 0xee
#define SUSP 0xed
#define xEOF 0xec
/*ftp*/
#define PRELIM 1
#define COMPLETE 2
#define CONTINUE 3
#define TRANSIENT 4
#define ERROR 5
#define RRQ 01
#define WRQ 02
#define DATA 03
#define ACK 04
#define REC_ESC '\377'
#define REC_EOR '\001'
#define REC_EOF '\002'
#define BLK_EOR 0x80
#define BLK_EOF 0x40
#define BLK_ERRORS 0x20
#define BLK_RESTART 0x10
#define BUFLEN 20
int len;
unsigned char buf[BUFLEN + 1];
static struct termios tin;
char *resolve_hostname(char *hostname) {
struct hostent *he;
struct in_addr **addr_list;
printf("Resolving hostname: %s\n", hostname);
if ((he = gethostbyname(hostname)) == NULL) {
herror("gethostbyname");
return NULL;
}
addr_list = (struct in_addr **)he->h_addr_list;
if (addr_list == NULL) {
return NULL;
}
printf("Resolved IP: %s\n", inet_ntoa(*addr_list[0]));
return inet_ntoa(*addr_list[0]);
}
/*
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;
}
*/
char *heartbled(int sock,char*msg){
char buffer[512]=("GET / HTTP/1.1\r\n\r\n");
// sprintf(msg,"GET / HTTP/1.1\r\n\r\n");
char rectv[512];
char*heart=(char*)malloc(30);
char*blead=(char*)malloc(20);
char*error=(char*)malloc(10);
send(sock, buffer, strlen(buffer) ,0);
recv(sock, heart, strlen (buffer)+1500 , 0);
printf("%s\n\n",heart);
free(heart);
send(sock, buffer, strlen(buffer) ,0);
recv(sock, blead, strlen (buffer)+1500 , 0);
printf("%s\n\n",blead);
free(blead);
send(sock, buffer, strlen(buffer) ,0);
recv(sock, error, strlen (buffer)+1500 , 0);
printf("%s",error);
free(error);
return error;
}
int main(int argc, char *argv[])
{
char *ip_address = resolve_hostname(argv[1]);
int nread; /* return from read() */
int nready;
int maxfd;
char buffer[512]=("GET / HTTP/1.1\r\n\r\n");
//ip= hostname_to_ip(hostname);
printf(" resolved to %s" , ip_address);
int sock = socket(AF_INET, SOCK_STREAM, 0);
server.sin_family = AF_INET;
if (argc < 2 ) {
server.sin_addr.s_addr = inet_addr("185.60.216.35");
}
else{
server.sin_addr.s_addr = inet_addr(ip_address);
}
int port = 80;
if (argc == 3) {
port = atoi(argv[2]); }
if (argc == 4)
{
}
printf("%s resolved to %s" , argv[1] , ip_address);
server.sin_port = htons(port);
connect(sock, (struct sockaddr *)&server, sizeof(server));
struct timeval ts;
ts.tv_sec = 1; // 1 second
ts.tv_usec = 0;
ssize_t numBytesRecv = 10;
char replyMessage[520];
char *replyMessage2[5200];
FILE *fp;
if ((fp=fopen("test2.html", "w"))==NULL) {
printf ("can't open file to write\n");
exit(1); };
/// ######################## ///
/*facebook*/
//dlugi.info 94.152.142.227
printf("port is: %d\n", port);
printf("host ip is %s\n", argv[1]);
printf("enter the , exemple:/index.aspx\n");
if (port==80){;
do
{
heartbled(sock,"GET / HTTP/1.1\r\n\r\n");
numBytesRecv = recv(sock, replyMessage, strlen (replyMessage)+255, 0);
printf("%s\n", replyMessage);
fprintf (fp, "%s\n", replyMessage);
memset(&replyMessage, 0, sizeof(replyMessage));
} while (numBytesRecv>0);
}
else {
while(1){
fd_set fds;
/* Set up polling. */
FD_ZERO(&fds);
if (sock != 0)
FD_SET(sock, &fds);
FD_SET(0, &fds);
// wait for data
int nready = select(sock + 1, &fds, (fd_set *) 0, (fd_set *) 0, &ts);
if (nready < 0) {
perror("select. Error");
return 1;
}
else if (nready == 0) {
ts.tv_sec = 1; // 1 second
ts.tv_usec = 0;
}
else if (sock != 0 && FD_ISSET(sock, &fds)) {
// start by reading a single byte
int rv;
if ((rv = recv(sock , buf , 1 , 0)) < 0){
return 1;}
else if (rv == 0) {
printf("Connection closed by the remote end\n\r");
return 0;
}
if (buf[0] == CMD) {
// read 2 more bytes
len = recv(sock , buf + 1 , 2 , 0);
if (len < 0){
return 1;}
else if (len == 0) {
printf("Connection closed by the remote end\n\r");
return 0;
}
//negotiate(sock, buf, 3);
}
else {
len = 1;
buf[len] = '\0';
printf("%s", buf);
fprintf(fp,"%s", buf);
fflush(0);
// tcflush(sock, 0);
}
}
else if (FD_ISSET(0, &fds)) {
buf[0] = getc(stdin); //fgets(buf, 1, stdin);
if (send(sock, buf, 1, 0) < 0)
return 1;
if (buf[0] == '\n') // with the terminal in raw mode we need to force a LF
putchar('\r');
}
}
}
printf("save co test2.html file\n");
fclose (fp);
}
No comments:
Post a Comment