• c/c++实现获取NOD32升级账号密码


    功能有待完善和添加


    #include <iostream>
    #include <ctime>
    #include <cstring>
    #include <string>
    #include <fstream>
    #include <sstream>
    #include <cstdlib>
    using namespace std;
    
    //通过Wget来获取网页
    string GetHtmlByWget(string url)
    {
    	//获取待下载网页文件名
    	string fileName = url.substr((int)url.find_last_of("/") + 1);
    	if(fileName != "")
    	{
    		string strCom = "wget -q "; //wget命令,-q表示不显示下载信息
    		strCom.append(url);
    		system(strCom.c_str()); //执行wget
    
    		ifstream fin(fileName.c_str());
    		if(!fin)
    		{
    			return "";
    		}
    		string strHtml = "";
    		char chTemp[1024] = "";
    		//读取网页文件到内存中
    		while(fin.getline(chTemp , 1024))
    		{
    			strHtml.append(string(chTemp));
    			strcpy(chTemp , "");
    		}
    		fin.close();
    		strCom = "del -f ";  //删除文件命令,-f表示直接删除不做任何提示
    		strCom.append(fileName);
    		system(strCom.c_str()); //删除刚才下载下来的文件
    		return strHtml; //返回网页源码
    	}
    	else
    	{
    		return "";
    	}
    }
    
    string GetHtmlPath(int y, int m, int d)
    {
    	stringstream str;
    	string now;
    	string path = "http://www.nod32jihuoma.cn/nod32-id/";
    
    	str << y + 1900;
    	str >> now;
    	path.append(now);
    	path.append("-");
    	now.clear();
    	str.clear();
    
    	int month = m + 1;
    	if(month / 10 == 0)
    	{
    		str << 0;
    		str >> now;
    		path.append(now);
    		now.clear();
    		str.clear();
    	}
    	str << month;
    	str >> now;
    	path.append(now);
    	path.append("-");
    	now.clear();
    	str.clear();
    
    	int day = d;
    	if(day / 10 == 0)
    	{
    		str << 0;
    		str >> now;
    		path.append(now);
    		now.clear();
    		str.clear();
    	}
    	str << day;
    	str >> now;
    	path.append(now);
    	path.append(".html");
    	now.clear();
    	str.clear();
    	return path;
    }
    
    
    
    void SearchData(int n)
    {
    	ofstream cout("key.txt");
    	const string key = "<div>用户名:";//13
    	const string value = " 密  码:";//14
    	time_t t = time(NULL);
    	struct tm* cur = localtime(&t);
    	int y = cur->tm_year;
    	int m = cur->tm_mon;
    	int d = cur->tm_mday;
    	for(int i = 0 ; i < n; i++)
    	{
    		int dd = d - i;
    		string path = GetHtmlPath(y, m, dd);
    		cout << "获取网址" << "\n" << path << endl;
    		string data = GetHtmlByWget(path);
    
    		//cout << data << endl;
    
    		cout << y + 1900 << "年" << m + 1 << "月" << dd << "日 " << endl; 
    		cout << "用户名:           密码:" <<endl;
    		for(size_t pos = 0; pos < data.size(); pos++)
    		{
    			size_t t = data.find(key,pos);
    			if(t == string::npos)
    				break;
    			t += 13;
    			for(int i = 1; i <= 14; i++,t++)
    			{
    				cout << data[t];
    			}
    			cout << "    ";
    			t += 14;
    			for(int i = 1; i <= 10; i++,t++)
    			{
    				cout << data[t];
    			}
    			pos = t;
    			cout << endl;
    		}
    	}
    	cout.close();
    }
    int main()
    {
    	SearchData(2);
    	
    	string str;
    	ifstream fin("key.txt");
    	while(fin)
    	{
    		getline(fin,str);
    		cout << str << endl;
    		str.clear();
    	}
    	fin.close();
    	return 0;
    }
    



    效果图:



    由于获取NOD32激活码的网址更改为http://www.nod32jihuoma.cn/nod32-id/index.html

    即不需要网址最后的时间的处理了,变得更加简单化

    相应的代码更改为:

    #include <iostream>
    #include <ctime>
    #include <cstring>
    #include <string>
    #include <fstream>
    #include <sstream>
    #include <cstdlib>
    #include <afxinet.h>
    using namespace std;
    
    string GetHtml(CString url)
    {
    	CString content;
    	CString data;
    	DWORD dwStatusCode;
    	CInternetSession session("HttpClient");
    
    	CHttpFile* pfile = (CHttpFile *)session.OpenURL(url);
    	pfile -> QueryInfoStatusCode(dwStatusCode);
    	if(dwStatusCode == HTTP_STATUS_OK)
    	{ 
    		while (pfile -> ReadString(data))
    		{
    			content  += data;
    		}
    	}
    	pfile -> Close();
    	delete pfile;
    	session.Close();
    	return string(content.GetBuffer(content.GetLength()));
    }
    
    void SearchData()
    {
    	ofstream cout("key.txt");
    	const string key = "</p><p>用户名:";//15
    	const string value = " 密  码:";//14
    	time_t t = time(NULL);
    	struct tm* cur = localtime(&t);
    	int y = cur->tm_year;
    	int m = cur->tm_mon;
    	int d = cur->tm_mday;
    	string path = "http://www.nod32jihuoma.cn/nod32-id/index.html";
    	cout << "获取网址" << "\n" << path << endl;
    	CString url;
    	url.Format("%s",path.c_str());
    	string data = GetHtml(url);
    
    	//cout << data << endl;
    
    	cout << y + 1900 << "年" << m + 1 << "月" << d << "日 " << endl; 
    	cout << "用户名:           密码:" <<endl;
    	for(size_t pos = 0; pos < data.size(); pos++)
    	{
    		size_t t = data.find(key,pos);
    		if(t == string::npos)
    			break;
    		t += 15;
    		for(int i = 1; i <= 14; i++,t++)
    		{
    			cout << data[t];
    		}
    		cout << "    ";
    		t += 14;
    		for(int i = 1; i <= 10; i++,t++)
    		{
    			cout << data[t];
    		}
    		pos = t;
    		cout << endl;
    	}
    	cout.close();
    }
    
    int main() 
    { 
    	SearchData();
    
    	string str;
    	ifstream fin("key.txt");
    	while(fin)
    	{
    		getline(fin,str);
    		cout << str << endl;
    		str.clear();
    	}
    	fin.close();
    	system("pause");
    	return 0;
    }  

    http://www.nod32jihuoma.cn/nod32-id/index.html


    #include <iostream>
    #include <ctime>
    #include <cstring>
    #include <string>
    #include <fstream>
    #include <sstream>
    #include <cstdlib>
    using namespace std;
    
    //通过Wget来获取网页
    string GetHtmlByWget(string url)
    {
    	//获取待下载网页文件名
    	string fileName = url.substr((int)url.find_last_of("/") + 1);
    	if(fileName != "")
    	{
    		string strCom = "wget -q "; //wget命令,-q表示不显示下载信息
    		strCom.append(url);
    		system(strCom.c_str()); //执行wget
    
    		ifstream fin(fileName.c_str());
    		if(!fin)
    		{
    			return "";
    		}
    		string strHtml = "";
    		char chTemp[1024] = "";
    		//读取网页文件到内存中
    		while(fin.getline(chTemp , 1024))
    		{
    			strHtml.append(string(chTemp));
    			strcpy(chTemp , "");
    		}
    		fin.close();
    		strCom = "del -f ";  //删除文件命令,-f表示直接删除不做任何提示
    		strCom.append(fileName);
    		system(strCom.c_str()); //删除刚才下载下来的文件
    		return strHtml; //返回网页源码
    	}
    	else
    	{
    		return "";
    	}
    }
    
    void SearchData()
    {
    	ofstream cout("key.txt");
    	const string key = "</p><p>用户名:";//15 
    	const string value = " 密  码:";//14
    	time_t t = time(NULL);
    	struct tm* cur = localtime(&t);
    	int y = cur->tm_year;
    	int m = cur->tm_mon;
    	int d = cur->tm_mday;
    		string path = "http://www.nod32jihuoma.cn/nod32-id/index.html";
    		cout << "获取网址" << "\n" << path << endl;
    		string data = GetHtmlByWget(path);
    
    		//cout << data << endl;
    
    		cout << y + 1900 << "年" << m + 1 << "月" << d << "日 " << endl; 
    		cout << "用户名:           密码:" <<endl;
    		for(size_t pos = 0; pos < data.size(); pos++)
    		{
    			size_t t = data.find(key,pos);
    			if(t == string::npos)
    				break;
    			t += 15;
    			for(int i = 1; i <= 14; i++,t++)
    			{
    				cout << data[t];
    			}
    			cout << "    ";
    			t += 14;
    			for(int i = 1; i <= 10; i++,t++)
    			{
    				cout << data[t];
    			}
    			pos = t;
    			cout << endl;
    		}
    	cout.close();
    }
    int main()
    {
    	SearchData();
    	
    	string str;
    	ifstream fin("key.txt");
    	while(fin)
    	{
    		getline(fin,str);
    		cout << str << endl;
    		str.clear();
    	}
    	fin.close();
    	system("pause");
    	return 0;
    }
    


  • 相关阅读:
    程序员这生必须掌握的两种图形
    用一张组织架构图说清楚类和对象
    简单工厂、工厂方法、抽象工厂的比较与分析
    rabbitmq系列(一)初识rabbitmq
    【最新】经典面试100问,附答案
    使用wordPress搭建个人博客
    调试接口你还在用postman吗
    Token ,Cookie、Session傻傻分不清楚?
    你不可不知的自定义注解
    使用aop加解密http接口
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/5835213.html
Copyright © 2020-2023  润新知