Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 连接到Wi-Fi C++;_C++_Windows_Wifi - Fatal编程技术网

C++ 连接到Wi-Fi C++;

C++ 连接到Wi-Fi C++;,c++,windows,wifi,C++,Windows,Wifi,我到处找。。。是的!我找不到任何关于如何> 连接到C++上的Wi-Fi的例子。 我在MSDN上找到并尝试了和的示例。我还在C#上找到了我正在搜索的内容的一个示例。有谁能告诉我一个关于C++的吗 编辑:我对C++的Internet部分(服务器、WiFi API甚至Win32 API)一无所知,只是语言的核心,我只想制作一个 >简单的程序,找到一个开放的连接,并且自动< /强>连接到它,并在连接成功时播放声音。如果你能给我提供一些信息和链接,我会做一个研究,然后发布我能找到的任何解决方案。好的,我想

我到处找。。。是的!我找不到任何关于<强>如何> <强>连接到C++上的Wi-Fi的例子。

我在MSDN上找到并尝试了和的示例。我还在C#上找到了我正在搜索的内容的一个示例。有谁能告诉我一个关于C++的吗


<>编辑:我对C++的Internet部分(服务器、WiFi API甚至Win32 API)一无所知,只是语言的核心,我只想制作一个<强> >简单的<强>程序,找到一个开放的连接,并且<强>自动< /强>连接到它,并在连接成功时播放声音。如果你能给我提供一些信息链接,我会做一个研究,然后发布我能找到的任何解决方案。

好的,我想你正在寻找一个枚举函数,比如这个:

我想你的意思是检查WLan状态是否正常。如果仔细观察,枚举函数将返回一个包含isState的结构,isState是以下内容之一:

typedef enum _WLAN_INTERFACE_STATE { 
  wlan_interface_state_not_ready              = 0,
  wlan_interface_state_connected              = 1,
  wlan_interface_state_ad_hoc_network_formed  = 2,
  wlan_interface_state_disconnecting          = 3,
  wlan_interface_state_disconnected           = 4,
  wlan_interface_state_associating            = 5,
  wlan_interface_state_discovering            = 6,
  wlan_interface_state_authenticating         = 7
} WLAN_INTERFACE_STATE, *PWLAN_INTERFACE_STATE;

要真正“连接”,您需要有一台服务器在另一端侦听。。。虽然Renan也给了你一个很好的链接(见问题的评论部分),但这需要你有一个SSID。这取决于您的软件是否真的知道Wifi SSID。

给定的代码不是高级类型,即不是很好,但它可以工作。我在windows中使用了代码块

#include <iostream>
#include<stdlib.h>
#include<fstream>
#include<string>
#include<conio.h>

using namespace std;

int main()
{
ofstream xmlFile;
ifstream xmlFile1;

string name="",pass="";
string ntyp="Wi-Fi",netType,fileTest=">test.txt",check,ntype,fil,xfileName,fileName="myWlan.xml";
char c='"',cho='2',cho1='1',c1;
netType=c+ntyp+c+fileTest;
xfileName=c+fileName+c;
int succ=0;

 do
 {
      system("netsh wlan show networks");
      cout<<"   >--------------------         TO REFRESS PRESS :1       \n\n   >--------------------         TO CHOOSE NETWORK PRESS : 2              \n\n   >   ";
      cho=getch();
}while(cho!='2');

cout<<"\n    Enter the desired network name-------:       ";
cin>>name;
do
{
   cout<<"\n    Enter wifi Password------:        ";
    cin>>pass;
    xmlFile.open(fileName.c_str());

    //Writing a xml file .....................

    xmlFile<<"<?xml version="<<c<<"1.0"<<c<<"?>\n";
    xmlFile<<"<WLANProfile xmlns="<<c<<"http://www.microsoft.com/networking/WLAN/profile/v1"<<c<<">\n";
    xmlFile<<"<name>";
    xmlFile<<name;
    xmlFile<<"</name>\n<SSIDConfig>\n<SSID>\n<hex>";
    for(int i=0;i<name.length();i++)
    xmlFile<<hex<<(int)name.at(i);
    xmlFile<<"</hex>\n<name>";
    xmlFile<<name;
    xmlFile<<"</name>\n</SSID>\n</SSIDConfig>\n<connectionType>ESS</connectionType>\n<connectionMode>auto</connectionMode>\n<MSM>\n<security>\n<authEncryption>";
    xmlFile<<"\n<authentication>WPA2PSK</authentication>\n<encryption>AES</encryption>\n<useOneX>false</useOneX>\n</authEncryption>\n<sharedKey>";
    xmlFile<<"\n<keyType>passPhrase</keyType>\n<protected>false</protected>\n<keyMaterial>";
    xmlFile<<pass;
    xmlFile<<"</keyMaterial>\n</sharedKey>\n</security>\n</MSM>\n";
    xmlFile<<"<MacRandomization xmlns="<<c<<"http://www.microsoft.com/networking/WLAN/profile/v3"<<c<<">\n";
    xmlFile<<"<enableRandomization>false</enableRandomization>\n</MacRandomization>\n</WLANProfile>";
    xmlFile.close();

    //addd the xml file to system profile.............
    system(("netsh wlan add profile filename="+xfileName).c_str());
    //to let system realize what changes have been made...............
    system("timeout /t 2");
    //to check if connected...........
    system(("netsh interface show interface name="+netType).c_str());

    xmlFile1.open("test.txt");
    while(!xmlFile1.eof())
    {
         xmlFile1>>c1;
         if(c1==':')
         {
              for(int i=0;i<9;i++)
              {
                   xmlFile1>>c1;
                   check=check+c1;
               }
         }
              if(check=="Connected")
              {
                  cout<<"...............................................You are connected!!.................................";
                  succ=1;break;
              }
              if(check!="Connected")check="";



    }
    xmlFile1.close();
    if(succ==1)break;
  }while(succ!=1);
return 0;
}
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
流xmlFile;
ifstreamxmlfile1;
字符串名称=”,传递=”;
字符串ntype=“Wi-Fi”,netType,fileTest=“>test.txt”,check,ntype,fil,xfileName,fileName=“myWlan.xml”;
字符c=''”,cho='2',cho1='1',c1;
netType=c+ntyp+c+fileTest;
xfileName=c+fileName+c;
int succ=0;
做
{
系统(“netsh wlan显示网络”);

就您而言,您只需连接到服务器(或创建要连接的服务器)。数据包的传输方式与您无关。无论如何,操作系统都会为您解决这一问题。我已经更新了我的帖子。@RenanGemignani我尝试了该函数,并查找了它使用的结构,但出现了一个错误\u SUCCESS,但它没有连接。如果我将ucSSID更改为不存在的ucSSID,它会再次返回成功。。它适用于断开连接,但不适用于vice versa。Windows不应该连接到Wifi吗?不是一些随机程序吗?只要我可以使用
WlanGetAvailableNetworkList()
获取SSID,那就不会有问题。如果你说的是隐藏的,我不会弄乱它们。