程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> C++實現模擬登錄---發送post表單信息包

C++實現模擬登錄---發送post表單信息包

編輯:C++入門知識

C++實現模擬登錄---發送post表單信息包


 

測試網址ip:222.73.24.32

測試帳號:lzh_2

密碼:123456789

 

首先要確定提交表單的信息,我用抓包工具抓了post的包,然後寫程序模擬發送過程,實現了登錄過程。

 

注意事項:

1.一定要按照抓包的信息發送,甚至空格、換行數都要一樣;

2.模擬登錄的網頁沒有驗證碼;

 

代碼:

 

//post發送表單信息模擬登錄
#include
#include
#include
#include
#include
#include
#pragma comment(lib, ws2_32.lib)

#define max 20480

using namespace std;

int main()
{
	int num,sum;

	SOCKET s;
	WSADATA wsa;
	struct sockaddr_in serv;

	char sndBuf[max], rcvBuf[max];

	WSAStartup(MAKEWORD(2, 1), &wsa);

	if ((s = socket(AF_INET, SOCK_STREAM, 0))<0)
	{
		perror(socket error!);
		exit(1);
	}

	memset(&serv,0,sizeof(serv));
	serv.sin_family = AF_INET;
	serv.sin_port = htons(80);
	//serv.sin_addr.s_addr = *((int*)*host_addr->h_addr_list);
	serv.sin_addr.S_un.S_addr = inet_addr(222.73.24.32);

	if ((connect(s, (struct sockaddr *)&serv, sizeof(serv)))<0)
	{
		perror(connet error!);
		exit(1);
	}

	memset(sndBuf, 0, max);
	memset(rcvBuf, 0, max);

	//頭信息
    strcat(sndBuf, POST );
    strcat(sndBuf, /inc/Check.asp HTTP/1.1
);
    strcat(sndBuf, x-requested-with: XMLHttpRequest
);
	strcat(sndBuf, Accept-Language: zh-cn
);
    strcat(sndBuf, Referer: http://user.exam8.com/user_login.asp);
    strcat(sndBuf, 
);
	strcat(sndBuf, Accept: */*
);
	strcat(sndBuf, Content-Type: application/x-www-form-urlencoded
);
	strcat(sndBuf, Accept-Encoding: gzip, deflate
);
	strcat(sndBuf, User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; eSobiSubscriber 1.0.0.40; MAAR; .NET4.0C; .NET4.0E; Maxthon/3.0)
);
	strcat(sndBuf, Host: user.exam8.com
);
	strcat(sndBuf, Content-Length: 61
);
	strcat(sndBuf, Connection: Keep-Alive
);
	strcat(sndBuf, Cache-Control: no-cache
);
	strcat(sndBuf, Cookie: Hm_lvt_80e97646f045b0632f81239c03c83492=1415795254,1415797440; referrer=http%3A//www.baidu.com/s%3Fwd%3D%25e8%2580%2583%25e8%25af%2595%25e5%2590%25a7%26rsv_spt%3D1%26issp%3D1%26f%3D3%26rsv_bp%3D0%26rsv_idx%3D2%26ie%3Dutf-8%26tn%3Dmaxthon2%26rsv_sug3%3D3%26rsv_sug4%3D126%26rsv_sug1%3D1%26oq%3Dkaoshi%26rsp%3D0%26rsv_sug5%3D0; CNZZDATA89268=cnzz_eid%3D1936228237-1415277587-http%253A%252F%252Fuser.exam8.com%252F%26ntime%3D1415871209; ASPSESSIONIDAARTBSDT=AGDHGJFCMKBDAGLGHINHACEN
);
	strcat(sndBuf, 
);
	strcat(sndBuf, Action=login&LoginUserName=lzh_2&LoginUserPassword=123456789&);
	

	puts(sndBuf);
  
	if ((num = send(s,sndBuf,max, 0))<0)
    {
		perror(send error!);
		exit(1);
	}
	
	puts(send success!
);

	sum = recv(s, rcvBuf, max-1, 0);//如果rcvBuf的存儲空間減小,則分幾次copy
	
	if(sum>0)
	{
		puts(OK!); 
		printf(%s,rcvBuf);
	}
	
	puts(
read success!
);
	
	closesocket(s);

	system(pause);
	WSACleanup();
	
	return 0;

}

運行結果:

 

1.發送信息

\

 

2.發送成功返回信息:

\

 

3.登錄成功返回信息:

\

 

4.輸入錯誤的用戶名或密碼:

\

\

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved