C++ 查看本機WiFi密碼

/*
	查看本機WiFi密碼
	時間:2020年5月7日11:24:26 
*/ 

#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
class Wifi{
	private:
		string name;
	public:
		Wifi(string _name):name(_name)
		{
			
		}
		string getName()
		{
			return this->name; 
		}
		
};

void showWifiPassword(Wifi wifi)
{
	string cmd="netsh wlan show profiles "+wifi.getName()+" key=clear >>1.tmp";
	system(cmd.c_str());
	FILE *fp;
	if((fp=fopen("1.tmp","r"))==NULL)
	{
		cout<<"file open error"<<endl;
	}
	char lineTxt[1024];
	for(int i=0;i<33;i++)
	{
		fgets(lineTxt,1024,fp);
	}
	
	string passwd=lineTxt;
	int c=passwd.find(':');
	passwd.erase(passwd.begin(),passwd.begin()+c+2);
	cout<<"Wifi Name:     "<<wifi.getName()<<endl;
	cout<<"Wifi Password: "<<passwd; 
	system("pause");
}
int main(int argc,char *argv[])
{
	if(argc<2)
	{
		cout<<"error"<<endl;
	}
	Wifi w(argv[1]);
	showWifiPassword(w);
	return 0;
} 
/*
	TP-LINK_E467
*/

使用方式,編譯完成之後,添加參數例如

我將上面代碼編譯show.exe

運行 show TP-LINK_E467

得到如下結果

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章