关于皓月Tunnuel联机(感谢皓哥一波),有个朋友用的是网卡重刷驱动连接pspWifi进行联机的,不过每次退出集会后都要点开电脑设置手动连接Wifi,于是萌生了个制作Wifi断线重连程序的想法。
基本想法是 system控制dos 来实现对wifi的控制
1、定时dos检测当前wifi连接状态
netsh wlan show interfaces
2、dos连接指定wifi
netsh wlan connect name=wifissid
不过还需要准备一些东西
1、在c++中控制dos可用system()函数,例如:
system("netsh wlan show interfaces");
2、c++中如何控制定时函数(python好方便啊!!!!!!)
找了半天用了settimer,但是还是不懂怎么用,于是直接套用别人的代码了
#include <stdlib.h>
#include <Windows.h>
#include <iostream>
using namespace std;
void Work()
{
cout<<"working~"<<endl;
}
VOID CALLBACK TimerProcess(HWND hwnd, UINT uMsg, UINT idEvent,DWORD dwTime)
{
Work();
}
int main()
{
cout <<"start"<<endl;
HWND hwndTimer;
MSG msg;
SetTimer(NULL,1,3000,TimerProcess);//三千毫秒间隔时间
int itemp;
while ((itemp = GetMessage(&msg, NULL,NULL,NULL))&& (itemp!=0) &&(-1 != itemp))
{
if(msg.message == WM_TIMER)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
需要使用的话把work()代码改一下就可以了,但是到现在还是不能理解(捂脸),只会套用
然后还需要识别dos命令的结果,不过好像没找到直接写入变量的方法,所以只能先写入文件中然后再从文件中读取
在dos命令后加上 >文件名.txt 就可以了
netsh wlan show interfaces > wifi_info.txt
最后贴上源码:
#include <stdlib.h>
#include <Windows.h>
#include <iostream>
#include <fstream>
using namespace std;
string name = "PSP_AULJM05800_L_MHP3Q000";
int GetWiFi(string wifiname)
{
char *filename = "wifi_info.txt";
string text;
ifstream f;
f.open(filename);
while(getline(f,text))
{
if (text.find(wifiname)>0&&text.find(wifiname)<=100) return 1;
}
return 0;
}
void Work(string wifiname)
{
system("netsh wlan show interfaces > wifi_info.txt");
int statue = GetWiFi(wifiname);
if(statue==0)
{
string body = "netsh wlan connect name=";
string S = body + wifiname;
char * s = (char*)S.data();
system(s);
}
}
VOID CALLBACK TimerProcess(HWND hwnd, UINT uMsg, UINT idEvent,DWORD dwTime)
{
Work(name);
}
int main()
{
cout <<"保持连接中......"<<endl;
HWND hwndTimer;
MSG msg;
SetTimer(NULL,1,3000,TimerProcess);
int itemp;
while ((itemp = GetMessage(&msg, NULL,NULL,NULL))&& (itemp!=0) &&(-1 != itemp))
{
if(msg.message == WM_TIMER)
{
//cout<<"test"<<endl;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
检测时间间隔为3秒,wifi名为”PSP_AULJM05800_L_MHP3Q000“,如果需要重连其它WiFi只需要把WiFi名改一下就可以了
欢迎守着psp的 萌死它夯它瓦鲁多 的猛汉们来 皓月tunuel联机平台 一起联机
(最后插一句:python真 * * 的方便啊!!!!!!但我这次还是不知道为什么用了c++)