能力值:
( LV2,RANK:10 )
|
-
-
2 楼
呵呵,已经发了一个示例给了老兄!
|
能力值:
( LV9,RANK:380 )
|
-
-
3 楼
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
include wsock32.inc
include Ws2_32.inc
includelib user32.lib
includelib kernel32.lib
includelib wsock32.lib
includelib Ws2_32.lib
TCP_PORT equ 80 ;常量定义
.data
@wsaData WSADATA <>
@stAddr sockaddr_in <>
szHostName db "www.pediy.com",0
sz3 db 156 dup(0)
sz1 db "GET /index.php HTTP/1.1",13,10
db "Host: www.pediy.com",13,10,13,10,0
.data?
hSocket SOCKET ?
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
invoke WSAStartup,202h,addr @wsaData ;初始化WSAStartup库
invoke WSASocket,PF_INET,SOCK_STREAM,IPPROTO_TCP,NULL,0,0 ;加载套接字
mov hSocket,eax ;保存句柄
invoke htons,TCP_PORT ;设置端口
mov @stAddr.sin_port,ax ;保存
invoke gethostbyname,addr szHostName
mov eax,[eax+hostent.h_list] ;指向两个指针,一是h_list,一是函数的返回值
mov eax,[eax] ;取出一个
mov eax,[eax] ;再取一个正好得到h_list,也就是玉米的IP的值
mov @stAddr.sin_addr,eax
mov @stAddr.sin_family,AF_INET ;设置IP格式
invoke bind,hSocket,addr @stAddr,sizeof @stAddr
invoke connect,hSocket,addr @stAddr,sizeof @stAddr
invoke lstrlen,addr sz1
invoke send,hSocket,addr sz1,eax,0
invoke recv,hSocket,addr sz3,3556,0
invoke MessageBox,NULL,addr sz3,NULL,MB_OK
invoke closesocket,hSocket
invoke ExitProcess,NULL
end start
|
能力值:
( LV9,RANK:1250 )
|
-
-
4 楼
OK,我知道你是谁了,呵呵,你就等着过几天警察去抓你吧。
|
能力值:
( LV9,RANK:1250 )
|
-
-
5 楼
我改写了一个C版本的:
//读取网页页面内容C版本
//HappyTown/[2007-05-16]
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include <windows.h>
#pragma comment(lib, "ws2_32.lib")
#define MAX 100000
int main()
{
int i;
SOCKET sc;
WSADATA wsaData;
SOCKADDR_IN scAddr;
HOSTENT * ht;
int RET;
unsigned char szPage[500] = "GET /showthread.php?t=44643 HTTP/1.1\r\nHost: bbs.pediy.com\r\n\r\n";
unsigned char Buffer[MAX] = {0};
FILE *fHtmlData;
WSAStartup(0x0202, &wsaData);
sc = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0);
ht = gethostbyname("bbs.pediy.com");
scAddr.sin_port = htons(80); //http
scAddr.sin_family = AF_INET;
scAddr.sin_addr.s_addr = *(unsigned long *)ht->h_addr_list[0];
//让它返回值,以便检测函数是否调用成功
RET = connect(sc, (SOCKADDR *)&scAddr, sizeof(scAddr));
RET = send(sc, szPage, lstrlen(szPage), 0);
RET = recv(sc, Buffer, MAX, 0);
//我们把信息写入文件
printf("将要写入文件.\n");
fHtmlData = fopen("download.txt", "w");
for (i=0; i<RET; i++)
{
fputc(Buffer[i], fHtmlData);
}
//延迟,等待页面出现,若太快,则不能用commview重新构建TCP会话的HTML版本
Sleep(5000);
WSACleanup();
system("pause");
return 0;
}
|
能力值:
( LV2,RANK:10 )
|
-
-
6 楼
你可以用libcurl库,很方便的。官方网站http://curl.haxx.se/libcurl/
|
能力值:
( LV9,RANK:380 )
|
-
-
7 楼
应该可以吧,我抓看雪主站就是返回它的内容。 但是论坛嘛,不如你先这样改看看:
szHostName db bbs.pediy.com",0
sz3 db 156 dup(0)
sz1 db "GET /showthread.php?t=44643 HTTP/1.1",13,10
db "Host: bbs.pediy.com",13,10,13,10,0
抓本帖的内容
|
能力值:
( LV9,RANK:1250 )
|
-
-
10 楼
Winker兄,后来发现你的这段代码获取的是http头信息:
=====================================
HTTP/1.1 200 OK
Connection: close
Date: Wed, 16 May 2007 23:33:55 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Set-Cookie: bblastvisit=1179358434; expires=Thu, 15-May-2008 23:33:54 GMT; path=/
Set-Cookie: bblastactivity=0; expires=Thu, 15-May-2008 23:33:54 GMT; path=/
Content-Type: text/html; charset=utf-8
Cache-Control: private
Pragma: private
============================
而不是页面内容。怎么回事?若要获取完整的IE所显示的内容,还应该有什么进一步的工作?
|
能力值:
( LV9,RANK:380 )
|
-
-
11 楼
invoke recv,hSocket,addr sz3,3556,0
把3556改大点就是了。
再丢个C的:
#include <winsock2.h>
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "ws2_32.lib")
char *HMod[] = { "GET","POST"};
char *HttpVer[] = { "HTTP/1.0", "HTTP/1.1"};
char *HAccept[] = { "Accept:"," image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"};
char *HContentTp[]= { "Content-Type:"," application/x-www-form-urlencoded"};
char *host[]= { "Host:"," www.dream2fly.net"};
char *HUserAgent[]= { "User-Agent:"," Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon)"};
char *HContentLg[]= { "Content-Length:"};
char temp1[1024],temp2[10240];
int ren = 0;
int main(int argc,char *argv[]){
WSADATA WSAData={0};
struct sockaddr_in ServerAddr={0};
SOCKET ServerSocket=0;
struct hostent *pHostent;
long lLen=0;
FILE *fp;
if(WSAStartup(MAKEWORD(2,2), &WSAData))
return 1;
ServerSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
pHostent = gethostbyname("www.dream2fly.net");
ServerAddr.sin_family = AF_INET;
ServerAddr.sin_addr.s_addr = *(long *)pHostent->h_addr_list[0];
ServerAddr.sin_port = htons(80);
memset(temp1,0,1024);
memset(temp2,0,10240);
sprintf(temp1,"%s %s %s\r\n"
"%s%s\r\n"
"%s%s\r\n"
"%s%s\r\n"
"%s%s\r\n"
"%s%s\r\n"
"\r\n",
HMod[0],"/test.php",HttpVer[1],
HAccept[0],HAccept[1],
HContentTp[0],HContentTp[1],
HUserAgent[0],HUserAgent[1],
host[0], host[1],
HContentLg[0]," 0"
);
//以上的几个部分可以用自己的代码代替进去,也可以用逗号后面的那个已定义的字符串带入(若是用这个,这个时候就是正常的数据).HAcceptCt[1]
connect(ServerSocket,(SOCKADDR *)&ServerAddr,sizeof(ServerAddr));
send(ServerSocket,temp1,strlen(temp1),0);
printf("send....");
while((ren = recv(ServerSocket,temp2+lLen,10240-lLen,0))>0)
{
lLen+=ren;
ren =0;
printf("\r\nrecv....%dBytes...\r\n",lLen);
}
temp2[lLen-1]='\0';
printf("%s",temp2);
fp=fopen("test.txt","w+");
fwrite(temp2, strlen(temp2), 1 ,fp);
fclose(fp);
printf("\r\nPress any key to exit....");
getchar();
return 0;
}
|