|
北京ADSL缺陷,不监测用户名,使用者利用多接口(网卡)可以获得成倍带宽和ip地址。
可以用下面代码测试:
声明:以下只作测试只用,连接自行建立多重连接,ip需在编译之前填写,不具备断点功能。
带宽测试推荐:vnstat
bitblade.c
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <string.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <pthread.h>
- #include <unistd.h>
- #include <stdlib.h>
- #define HTTP_PORT 80
- #define FTP_PORT 21
- int BLADE;
- extern int h_errno;
- char host[255],filename_with_path[255],proto[5],filename[128];
- unsigned int protocol=0;
- char *ui_to_a(unsigned int i);
- struct sch{
- unsigned char status;
- unsigned int begin_p;
- unsigned int cur_p;
- unsigned int down_len;
- }sch1[255];
- void *ana_url(char *p){
- int n;
- /* judge the protocol e.g:[url]http://www.bit.edu.cn/file/big.zip[/url]
- the protocol is http
- */
- n=strlen(p)-strlen(strchr(p,':'));
- if(n>4)
- printf("URL error!You must indicate the Protocol,e.g:[url]http://~[/url]"); strncpy(proto,p,n);
- proto[n]='\0';
- lower(proto);
- if(strncmp(proto,"http",4)==0){
- protocol=1;
- }else if(strncmp(proto,"ftp",4)==0){
- protocol=2;
- }else{
- printf("Protocol Unkown\n");
- exit(1);
- }
- /* judge the hostname e.g:[url]www.bit.edu.cn*/[/url]
- p=strchr(p,':')+3;
- n=strlen(p)-strlen(strchr(p,'/'));
- strncpy(host,p,n);
- host[n]='\0';
- /* judge the filename_with_path e.g:/file/big.zip*/
- p=strchr(p,'/');
- n=strlen(p);
- strncpy(filename_with_path,p,n);
- filename_with_path[n]='\0';
- /* judge the filename without path*/
- p=strrchr(p,'/');
- n=strlen(p)-1;
- strncpy(filename,p+1,n);
- filename[n]='\0';
- return NULL;
- }
- /* open the part of file */
- int open_t_file(int t_no){
- char t_filename[255];
- char t_no_char[20];
- char *f;
- int n,ffd;
- n=strlen(filename);
- strncpy(t_filename,filename,n);
- t_filename[n]='_';
- t_filename[n+1]='t';
- t_filename[n+2]='\0';
- f=ui_to_a(t_no);
- printf("\n%s\n",f);
- strncat(t_filename,f,strlen(f));
- ffd=open(t_filename,O_RDWR|O_CREAT);
- return ffd;
- }
- int bind_sock(int t_cur){
- struct sockaddr_in remote_addr;
- int sockfd;
- struct hostent *h;
- /* create socket,enter ur IP here */
-
- char myhost[]="61.51.105.186";
- char myhost1[]="61.51.105.175";
- char *p;
- if(t_cur%2==0){
- p=myhost;
- }else{
- sleep(1);
- p=myhost1;
- }
-
- if(!(h=gethostbyname(myhost1))){
- printf("Hostname Unkown\n");
- exit(1);
- }else{
- printf("Hostname Converted\n");
- }
- write(1,p,13);
- sockfd=socket(AF_INET,SOCK_STREAM,0);
- bzero(&remote_addr,sizeof(remote_addr));
- remote_addr.sin_family=AF_INET;
- remote_addr.sin_port=htons(12435+t_cur);
- remote_addr.sin_addr.s_addr=inet_addr(p);
-
- printf("p is:%d",remote_addr.sin_addr.s_addr);
- if(bind(sockfd,(struct sockaddr *)&remote_addr,sizeof(remote_addr))<0){
- printf("Bind Error\n");
- exit(1);
- }else{
- printf("Socket Binded\n");
- }
- return sockfd;
- }
- int creat_sock(int sockfd){
- struct sockaddr_in remote_addr;
- struct hostent *h;
- /* create socket */
- if(!(h=gethostbyname(host))){
- printf("Hostname Unkown\n");
- exit(1);
- }else{printf("Hostname Converted\n");}
- bzero(&remote_addr,sizeof(remote_addr));
- remote_addr.sin_family=AF_INET;
- remote_addr.sin_port=htons(HTTP_PORT);
- bcopy(h->h_addr,(char *)&remote_addr.sin_addr,h->h_length);
- if(connect(sockfd,(struct sockaddr *)&remote_addr,sizeof(remote_addr))<0){
- printf("Connect Error\n");
- exit(1);
- }else{
- printf("Socket Created\n");
-
- }
- return sockfd;
- }
- int
- main(int argc,char *argv[]){
- char *p=argv[2];
- BLADE=atoi(argv[1]);
- ana_url(p);
- bzero(&sch1[0],13*255);
- printf("Your required filename is: %s\n",filename);
- bhttp();
- exit(0);
- }
复制代码
bhttp.c
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <string.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <pthread.h>
- #include <unistd.h>
- #include <stdlib.h>
- int BLADE;
- char host[255],filename_with_path[255],proto[5],filename[128];
- unsigned int http_content_len=0;
- pthread_t http_get_t[10];
- struct sch{
- unsigned char status;
- unsigned int begin_p;
- unsigned int cur_p;
- unsigned int down_len;
- }sch1[255];
- char *ui_to_a(unsigned int i);
- char *form_http_request(char *p,int begin_p){
- char *q;
- strncat(p,filename_with_path,strlen(filename_with_path));
- strncat(p," HTTP/1.1\r\n",11);
- strncat(p,"Host:",5);
- strncat(p,host,strlen(host));
- strncat(p,"\r\nAccept:*/*\r\n",15);
- strncat(p,"Range:bytes=",13);
- q=ui_to_a(begin_p);
- strncat(p,q,strlen(q));
- strncat(p,"-\r\n\r\n",5);
- return p;
- }
- void *t_http_get(void *arg){
- char *p;
- int n,t_cur;
- int sockfd,ffd;
- unsigned int need_wr;
- unsigned int header_len,got_p_content_addr=0,got_p_length_addr=0;
- char http_request[1024]="GET ";
- unsigned char retry=0;
- int nn;
- unsigned int need_wr_once=0;
- unsigned int got_len;
- char *q;
- char http_content_len_char[22];
- char recv_data[1024*256];
- t_cur=arg;
- if(sch1[0].down_len==0){
- nn=BLADE;
- }else{
- nn=t_cur;
- }
- sockfd=bind_sock(nn);
- sockfd=creat_sock(sockfd);
- sch1[t_cur].status=1;
- sch1[t_cur].begin_p=(t_cur)*(http_content_len/BLADE);
- p=http_request;
- form_http_request(p,sch1[t_cur].begin_p);
- if(t_cur!=BLADE-1){
- need_wr=sch1[t_cur].down_len=http_content_len/BLADE;
- }else{
- need_wr=sch1[t_cur].down_len=http_content_len/BLADE+http_content_len%BLADE;
- }
- printf("down_len=%d\n",sch1[t_cur].down_len);
- if(sch1[0].down_len!=0)
- ffd=open_t_file(t_cur);
- write(sockfd,p,strlen(p));
- while(1){
- for(got_len=0;got_len<sizeof(recv_data);got_len+=n){
- n=read(sockfd,&recv_data[got_len],sizeof(recv_data)-got_len);
- if(n<0)
- printf("socket read error!");
- if(n==0)
- retry+=1;
- if(retry>=3)
- break;
- }
- if(sch1[0].down_len==0&&(p=strstr(recv_data,"\nContent-Length: "))!=NULL&&got_p_length_addr==0){
- q=strchr(p+1,'\n');
- got_p_length_addr=1;
- strncpy(http_content_len_char,p+17,q-p-18);
- http_content_len_char[q-p-18]='\0';
- http_content_len=atoi(http_content_len_char);
- printf("The total http_content_len is:%d",http_content_len);
- sch1[0].down_len=http_content_len/BLADE;
- break;
- }
-
- if((p=strstr(recv_data,"\r\n\r\n"))!=NULL&&got_p_content_addr!=1){
- header_len=p-&recv_data[0]+4;
- got_p_content_addr=1;
- got_len-=header_len;
- p+=4;
- }else{
- p=recv_data;
- }
- if(got_len<=need_wr){
- need_wr_once=got_len;
- }else{
- need_wr_once=need_wr;
- }
- printf("got_len==%d\n",got_len);
- nn=write(ffd,p,need_wr_once);
- sch1[t_cur].cur_p+=nn;
- need_wr-=nn;
- if(need_wr<=0)
- break;
- }
- return NULL;
- }
- void bhttp(){
- int i;
- if(pthread_create(&http_get_t[0],NULL,t_http_get,0)){
- printf("error creating thread.");
- exit(1);
- }else{
- printf("thread created.\n");
- }
- while(sch1[0].down_len==0)
- sleep(1);
- for(i=0;i<BLADE;i++){
- if(pthread_create(&http_get_t[i+1],NULL,t_http_get,i)){
- printf("error creating thread.");
- exit(1);
- }else{
- printf("thread created.\n");
- }
- }
- for(i=0;i<BLADE+1;i++){
- if(pthread_join(http_get_t[i],NULL)){
- printf("error joining thread.");
- exit (1);
- }
- }
- }
复制代码
itoa.c
- /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2002
- Free Software Foundation, Inc.
- Written by James Clark (jjc@jclark.com)
- This file is part of groff.
- groff is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free
- Software Foundation; either version 2, or (at your option) any later
- version.
- groff is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- for more details.
- You should have received a copy of the GNU General Public License along
- with groff; see the file COPYING. If not, write to the Free Software
- Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
- #define INT_DIGITS 19 /* enough for 64 bit integer */
- #define UINT_DIGITS 20
- char *i_to_a(i)
- int i;
- {
- /* Room for INT_DIGITS digits, - and '\0' */
- static char buf[INT_DIGITS + 2];
- char *p = buf + INT_DIGITS + 1; /* points to terminating '\0' */
- if (i >= 0) {
- do {
- *--p = '0' + (i % 10);
- i /= 10;
- } while (i != 0);
- return p;
- }
- else { /* i < 0 */
- do {
- *--p = '0' - (i % 10);
- i /= 10;
- } while (i != 0);
- *--p = '-';
- }
- return p;
- }
- char *ui_to_a(i)
- unsigned int i;
- {
- /* Room for UINT_DIGITS digits and '\0' */
- static char buf[UINT_DIGITS + 1];
- char *p = buf + UINT_DIGITS; /* points to terminating '\0' */
- do {
- *--p = '0' + (i % 10);
- i /= 10;
- } while (i != 0);
- return p;
- }
复制代码
- /* make every char lowercase */
- void lower(char abc[]){
- int ii;
- for(ii=0;ii<=strlen(abc);ii++)
- abc[ii]=tolower(abc[ii]);
- }
复制代码
makefile
- bb:bitblade.c ast.c bhttp.c itoa.c
- gcc -o bb bitblade.c ast.c bhttp.c itoa.c -lpthread
复制代码 |
|