c - How can I bypass websites that block direct connections? -
i'm trying access website https://www.000webhost.com
c sockets:
#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(int argc, char** argv) { struct sockaddr_in servaddr; struct hostent *hp; int sock_id; char message[1024*1024]; char request[] = "get / http/1.1\n" "from: ...\n"; //get socket if((sock_id = socket(af_inet, sock_stream, 0)) == -1) { fprintf(stderr,"couldn't socket.\n"); exit(exit_failure); }else { fprintf(stderr,"got socket.\n"); } memset(&servaddr,0,sizeof(servaddr)); //get address if((hp = gethostbyname("000webhost.com")) == null) { fprintf(stderr,"couldn't address.\n"); exit(exit_failure); }else { fprintf(stderr,"got address.\n"); } memcpy((char *)&servaddr.sin_addr.s_addr, (char *)hp->h_addr, hp->h_length); //port number , type servaddr.sin_port = htons(80); servaddr.sin_family = af_inet; //connect if(connect(sock_id, (struct sockaddr *)&servaddr, sizeof(servaddr)) != 0) { fprintf(stderr, "couldn't connect.\n"); }else { fprintf(stderr,"got connection.\n"); } //request write(sock_id,request,strlen(request)); //response read(sock_id,message,1024*1024); fprintf(stdout,"%s",message); return 0; }
if change request[]
array "get / http/1.1\n" "from: ...\n"
"get / http/1.1\n" "host: https://www.000webhost.com" "from: ...\n"
(therefore removing direct-ip adress request), still error error 1003. direct ip access not allowed
. there other part of request need modify? else need do?
your request malformed:
each line needs terminated
\r\n
, not\n
. (some web servers let away\n
, have no idea whether that'll work on 000webhost.)every header needs
\r\n
after it. modified code mention in last paragraph missing\r\n
@ end ofhost
header.the
host
header needs hostname (e.g,"host: example.com"
). don't includehttp://
.
Comments
Post a Comment