91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-06
  • 語言: C/C++
  • 標簽: 提取網頁??

資源簡介

linux下C/C++實現已知url通過socket訪問網頁并獲得網頁文字內容

資源截圖

代碼片段和文件信息

#include?
#include??
#include??
#include??
#include?
#include??
#include??
#include??
#include??
#include??
#include??
#include??
#include??
#include??

#define?PORT?80?
#define?BUFSIZE?4092?

int?main(int?argc?char?*argv[])?
{
FILE?*?fp;
int?sockfd;
int?ret;
int?i;
int?h;?
struct?hostent?*?host;
struct?sockaddr_in?servaddr;?
char?str1[4096];
char?buf[BUFSIZE];
char?*str;
socklen_t?len;?
fd_set?t_set1;?
struct?timeval?tv;
host?=?gethostbyname(argv[1]);
fp?=?fopen(“/root/writeurl.txt““a“);
if(fp? {
printf(“open?file?fail...\n“);
return?-1;
}?

if?((sockfd?=?socket(AF_INET?SOCK_STREAM?0))? {?
printf(“socket?error!\n“);?
exit(0);
};?

bzero(&servaddr?sizeof(servaddr));?
servaddr.sin_family?=?AF_INET;?
servaddr.sin_port?=?htons(PORT);
servaddr.sin_addr?=?*((struct?in_addr*)host->h_addr);?
if?(connect(sockfd?(struct?sockaddr?*)&servaddr?sizeof(servaddr))? {?????
printf(“connect?error!\n“);?
exit(0);?
}?
printf(“connect?success?\n“);?

memset(str1?0?4096);?
sprintf(str1“GET?/?HTTP/1.0\r\nHost:%s\r\nContent-Type=text/plain\r\nConnection:Close\r\n\r\n“argv[1]);
ret?=?send(sockfd(void?*)str1strlen(str1)0);?
if?(ret? {?
printf(“send?error?%d,Error?message‘%s‘\n“errno?strerror(errno));?
exit(0);?
}
else
{?
printf(“send?success?total?send?%d?\n“?ret);?
}?
while(1)
{?
tv.tv_sec=?0;?
tv.tv_usec=?0;?
h=?0;?
FD_ZERO(&t_set1);?
FD_SET(sockfd?&t_set1);?
h=?select(sockfd?+1?&t_set1?NULL?NULL?&tv);?
if?(h?==?0)?continue;?
if?(h? {?
close(sockfd);?
printf(“some?thing?read?error!\n“);?
return?-1;?
};?
if?(h?>?0)
{?
memset(buf?0?4095);?
i=?recv(sockfd?(void?*)buf?40920);?
if?(i==0)
{?
close(sockfd);?
printf(“read?message?find?stop!\n“);?
return?-1;?
}?


fwrite(buf1ifp);
printf(“%s\n“?buf);?
}?
}?
fclose(fp);
close(sockfd);?
return?0;?
}


?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????2098??2013-04-07?16:16??第二題\url.c

?????目錄??????????0??2013-04-10?14:41??第二題

-----------?---------??----------?-----??----

?????????????????2098????????????????????2


評論

共有 條評論