IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage C++ Discussion :

Scanne de réseaux Wifi


Sujet :

Langage C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juin 2011
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2011
    Messages : 5
    Par défaut Scanne de réseaux Wifi
    Bonjour,

    J'ai monté un projet de scan de réseaux Wifi, le tout sous seven voulant m'essayer à la programmation sous Windows en C++.

    J'ai donc lu la documentation microsoft, et le tutoriel
    http://ram-0000.developpez.com/tutor...t-native-wifi/
    http://ram-0000.developpez.com/tutor...e/WifiScanner/

    Durant ce projet je voudrais récupérer le SSID, la MAC adresse, le Rssi et le channel.

    Or en regardant la doc Microsoft je vois que je peut utiliser WlanGetAvailableNetworkList() mais celui la ne me permet pas d'avoir la MAC Adresse qui est essentielle. Je me tourne alors vers WlanGetNetworkBssList()
    qui lui me permet de tout avoir.
    Mais il y a une chose que j'ai du mal a comprendre,

    Ouvre un Handle avec WlanOpenHandle
    Puis on récupère les interfaces avec WlanEnumInterfaces

    C'est ensuite que mon esprit se brouille, faut-il utiliser WlanGetAvailableNetworkList puis WlanGetNetworkBssList

    ou bien WlanGetNetworkBssList tout seul

    dans le cas de l'un après l'autre, je ne comprend ni ne voit le lien entre les deux

    Merci de votre aide

  2. #2
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Juin 2011
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2011
    Messages : 5
    Par défaut
    En reprenant du code j'ai réussi à avoir ceci


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    #include "stdafx.h"
    #include "scan.h"
     
     
     
     
    void scan::scanReseauWifi()const{
     
       DWORD negotiatedVersion = 0;
       HANDLE clientHandle = NULL;
       DWORD lastError;
     
       _tsetlocale(LC_ALL, _T(""));
     
       lastError = WlanOpenHandle(WLAN_API_VERSION, NULL, &negotiatedVersion, &clientHandle); /* open the Wifi box */
     
       if(lastError != ERROR_SUCCESS)
       {
          _tprintf(_T("Error in the WlanOpenHandle() function call"), lastError);
       }
       else
       {
          _tprintf(_T("Asked version to WLAN interface is %lu, negociated version is %lu\n"), 
                   WLAN_API_VERSION, negotiatedVersion);
     
          EnumerateInterface(clientHandle);
     
          lastError = WlanCloseHandle(clientHandle, NULL);
     
          if(lastError != ERROR_SUCCESS)
          {
             _tprintf(_T("Error in the WlanCloseHandle() function call"), lastError);
          }
       }//else
    }//END
     
     
     
    void DisplayError(LPCTSTR message, DWORD lastError)
    {
       LPTSTR buffer = NULL;
       if(message == NULL){message = _T("Error");}
     
       if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, lastError, 0, (LPTSTR)&buffer, 0, NULL) == 0)
       {
          if(GetLastError() == ERROR_NOT_ENOUGH_MEMORY)
          {
             _ftprintf(stderr, _T("%s : not enough memory\n"), message);
          }
          else
          {
             _ftprintf(stderr, _T("FormatMessage() failed : %lu\n"), GetLastError());
          }
       }
       else
       {
          _ftprintf(stderr, _T("%s : %s\n"), message, buffer);
          LocalFree(buffer), buffer = NULL;
       }
    }
     
    void DisplayAuthAlgorithm(DOT11_AUTH_ALGORITHM authAlgorithm)
    {
       LPCTSTR algo = NULL;
     
       switch(authAlgorithm)
       {
          case DOT11_AUTH_ALGO_80211_OPEN :         algo = _T("IEEE 802.11 Open System"); break;
          case DOT11_AUTH_ALGO_80211_SHARED_KEY :   algo = _T("802.11 Shared Key"); break;
          case DOT11_AUTH_ALGO_WPA :                algo = _T("WPA"); break;
          case DOT11_AUTH_ALGO_WPA_PSK :            algo = _T("WPA-PSK"); break;
          case DOT11_AUTH_ALGO_WPA_NONE :           algo = _T("not supported"); break;
          case DOT11_AUTH_ALGO_RSNA :               algo = _T("802.11i RSNA (WPA2)"); break;
          case DOT11_AUTH_ALGO_RSNA_PSK :           algo = _T(" 802.11i RSNA PSK (WPA2-PSK)"); break;
       }
     
       if(algo == NULL)
       {
          if(authAlgorithm >= DOT11_AUTH_ALGO_IHV_START && authAlgorithm <= DOT11_AUTH_ALGO_IHV_END)
          {
             algo = _T("Proprietary auth algorithm");
          }
          else
          {
             algo = _T("Unknown algorithm");
          }
       }
     
       _tprintf(_T("\t\tAuth Algorithm is [%s]\n"), algo);
    }
     
    LPCTSTR PhysicalTypeToString(DOT11_PHY_TYPE physicalType)
    {
       LPCTSTR type = NULL;
     
       switch(physicalType)
       {
          case dot11_phy_type_unknown :    type = _T("unknown or uninitialized PHY type"); break;
          case dot11_phy_type_fhss :       type = _T("frequency-hopping spread-spectrum (FHSS) PHY. Bluetooth devices can use FHSS or an adaptation of FHSS"); break;
          case dot11_phy_type_dsss :       type = _T("direct sequence spread spectrum (DSSS) PHY type"); break;
          case dot11_phy_type_irbaseband : type = _T("infrared (IR) baseband PHY type"); break;
          case dot11_phy_type_ofdm :       type = _T("orthogonal frequency division multiplexing (OFDM) PHY type. 802.11a devices can use OFDM"); break;
          case dot11_phy_type_hrdsss :     type = _T("high-rate DSSS (HRDSSS) PHY type"); break;
          case dot11_phy_type_erp :        type = _T("extended rate PHY type (ERP). 802.11g devices can use ERP"); break;
       }
     
       if(type == NULL)
       {
          if(physicalType >= dot11_phy_type_IHV_start && physicalType <= dot11_phy_type_IHV_end)
          {
             type = _T("Proprietary Physical Type");
          }
          else
          {
             type = _T("Unknown Physical Type");
          }
       }
     
       return type;
    }
     
    LPCTSTR StateToString(WLAN_INTERFACE_STATE state)
    {
       LPCTSTR status = NULL;
     
       switch(state)
       {
          case wlan_interface_state_not_ready :              status = _T("not ready");              break;
          case wlan_interface_state_connected :              status = _T("connected");              break;
          case wlan_interface_state_ad_hoc_network_formed :  status = _T("No peer has connected");  break;
          case wlan_interface_state_disconnecting :          status = _T("disconnecting");          break;
          case wlan_interface_state_disconnected :           status = _T("disconnected");           break;
          case wlan_interface_state_associating :            status = _T("associating");            break;
          case wlan_interface_state_discovering :            status = _T("discovering");            break;
          case wlan_interface_state_authenticating :         status = _T("authenticating");         break;
          default :                                          status = _T("unknown state");          break;
       }
     
       return status;
    }
     
    void DisplayBssType(DOT11_BSS_TYPE bssType)
    {
       LPCTSTR type;
     
       if(bssType == dot11_BSS_type_infrastructure)
       {
          type = _T("infastructure");
       }
       else if(bssType == dot11_BSS_type_independent)
       {
          type = _T("ad hoc");
       }
       else if(bssType == dot11_BSS_type_any)
       {
          type = _T("infastructure, ad hoc");
       }
       else
       {
          type = _T("unknown");
       }
     
       _tprintf(_T("\t\tNetwork type is [%s]\n"), type);
    }
     
    void DisplayProfileName(BOOL hasProfile, LPCWSTR profileName)
    {
       if(hasProfile)
       {
          _tprintf(_T("\t\tProfile name is %ws\n"), profileName);
       }
       else
       {
          _putts(_T("\t\tThere is no profile associated with this network"));
       }
    }
     
    void DisplaySSID(PDOT11_SSID ssid)
    {
       _tprintf(_T("\t\tSSID is [%.*hs]\n"), (int)(ssid->uSSIDLength), ssid->ucSSID);
    }
     
    void DisplayBSSID(HANDLE clientHandle, const GUID * interfaceGuid)
    {
       DWORD size = 0;
       PWLAN_CONNECTION_ATTRIBUTES attributes = NULL;
       DWORD lastError = WlanQueryInterface(clientHandle, interfaceGuid, wlan_intf_opcode_current_connection, NULL, &size, (PVOID*)&attributes, NULL);
     
       if(lastError == ERROR_SUCCESS)
       {
          PUCHAR bssid = attributes->wlanAssociationAttributes.dot11Bssid;
          _tprintf(_T("\t\tBSSID is %02X-%02X-%02X-%02X-%02X-%02X\n"), 
                   bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
          WlanFreeMemory(attributes), attributes = NULL;
       }
       else
       {
          _tprintf(_T("Error in the WlanQueryInterface() function call"), lastError);
       }
    }
     
    void DisplayConnectability(BOOL isConnectable, WLAN_REASON_CODE reasonCode)
    {
       if(isConnectable)
       {
          _putts(_T("\t\tNetwork is connectable"));
       }
       else
       {
          WCHAR reason[128];
          DWORD lastError = WlanReasonCodeToString(reasonCode, _countof(reason), reason, NULL);
     
          if(lastError == ERROR_SUCCESS)
          {
             _tprintf(_T("\t\tNetwork is not connectable : %ws\n"), reason);
          }
          else
          {
             DisplayError(_T("Error in the WlanReasonCodeToString() function call"), lastError);
          }
       }
    }
     
    void DisplayPhyTypes(HANDLE clientHandle, const GUID * interfaceGuid, WLAN_AVAILABLE_NETWORK * info)
    {
       ULONG type = 0;
       PWLAN_BSS_LIST list = NULL;
       DWORD lastError;
     
       if(info->uNumberOfPhyTypes > 1)
       {
          _tprintf(_T("\t\tThere are %lu physical types supported :"), info->uNumberOfPhyTypes);
       }
       else
       {
          _putts(_T("\t\tThere is 1 physical types supported :"));
       }
     
       for(; type < info->uNumberOfPhyTypes; type++)
       {
          _tprintf(_T("\t\t\t- %s\n"), PhysicalTypeToString(info->dot11PhyTypes[type]));
       }
     
       lastError = WlanGetNetworkBssList(clientHandle, interfaceGuid, &info->dot11Ssid, info->dot11BssType, 
                                         info->bSecurityEnabled, NULL, &list);
     
       if(lastError == ERROR_SUCCESS)
       {
     
          if(list->dwNumberOfItems == 1)
          {
             _tprintf(_T("\t\tPhysical type used for this network : %s\n"), 
                      PhysicalTypeToString(list->wlanBssEntries[0].dot11BssPhyType));
          }
     
           WlanFreeMemory(list), list = NULL;
       }
       else if(lastError != ERROR_NOT_SUPPORTED)
       {
          DisplayError(_T("Error in the WlanGetNetworkBssList() function call"), lastError);
       }
    }
     
    void DisplayStatus(BOOL isConnected)
    {
       _tprintf(_T("\t\tStatus : %s\n"), isConnected ? _T("connected") : _T("disconnected"));
    }
     
    void DisplaySecurity(BOOL isSecure, DOT11_CIPHER_ALGORITHM cipherAlgorithm)
    {
       if(isSecure)
       {
          LPCTSTR algo = NULL;
     
          switch(cipherAlgorithm)
          {
             case DOT11_CIPHER_ALGO_NONE :          algo = _T("No cipher");                   break;
             case DOT11_CIPHER_ALGO_WEP40 :         algo = _T("WEP (40 bits cipher key)");    break;
             case DOT11_CIPHER_ALGO_TKIP :          algo = _T("TKIP");                        break;
             case DOT11_CIPHER_ALGO_CCMP :          algo = _T("AES-CCMP");                    break;
             case DOT11_CIPHER_ALGO_WEP104 :        algo = _T("WEP (104 bits cipher key)");   break;
             case DOT11_CIPHER_ALGO_WEP :           algo = _T("WEP");                         break;
             case DOT11_CIPHER_ALGO_WPA_USE_GROUP : algo = _T("Use Group Key cipher suite");  break;
          }
     
          if(algo == NULL)
          {
             if(cipherAlgorithm >= DOT11_CIPHER_ALGO_IHV_START && cipherAlgorithm <= DOT11_CIPHER_ALGO_IHV_END)
             {
                algo = _T("Proprietary cipher algorithm");
             }
             else
             {
                algo = _T("Unknown algorithm");
             }
          }
     
          _tprintf(_T("\t\tSecurity is enbled : %s\n"), algo);
       }
       else
       {
          _putts(_T("\t\tSecurity is disabled"));
       }
    }
    void DisplaySignalStrength(WLAN_SIGNAL_QUALITY quality)
    {
    	int iRSSI;
        if (quality == 0)
            iRSSI = -100;
        else if (quality == 100)   
            iRSSI = -50;
        else
            iRSSI = -100 + (quality/2);    
     
        wprintf(L"  Signal Quality :\t %u (RSSI: %i dBm)\n", 
            quality, iRSSI);
       //_tprintf(_T("\t\tSignal strength is %lu%%\n"), quality);
    }
     
    void EnumerateNetwork(HANDLE clientHandle, const GUID * interfaceGuid)
    {
       WLAN_AVAILABLE_NETWORK_LIST * networkList = NULL;
       DWORD lastError = WlanGetAvailableNetworkList(clientHandle, interfaceGuid, 0, NULL, &networkList);
     
       if(lastError != ERROR_SUCCESS)
       {
          DisplayError(_T("Error in the WlanGetAvailableNetworkList() function call"), lastError);
       }
       else
       {
          _tprintf(_T("\tThere are %lu Wifi network\n"), networkList->dwNumberOfItems);
     
          for(networkList->dwIndex = 0; networkList->dwIndex != networkList->dwNumberOfItems; networkList->dwIndex++)
          { 
             WLAN_AVAILABLE_NETWORK * info = &networkList->Network[networkList->dwIndex];
     
             _tprintf(_T("\n\t\tNetwork %lu\n"), networkList->dwIndex);
             DisplayStatus(info->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED);
             DisplayProfileName(info->dwFlags & WLAN_AVAILABLE_NETWORK_HAS_PROFILE, info->strProfileName);
             DisplaySSID(&info->dot11Ssid);
             DisplayBssType(info->dot11BssType);
             DisplayBSSID(clientHandle, interfaceGuid);
             DisplayConnectability(info->bNetworkConnectable, info->wlanNotConnectableReason);
             DisplayPhyTypes(clientHandle, interfaceGuid, info);
             DisplaySecurity(info->bSecurityEnabled, info->dot11DefaultCipherAlgorithm);
             DisplaySignalStrength(info->wlanSignalQuality);
             DisplayAuthAlgorithm(info->dot11DefaultAuthAlgorithm);
          }
     
          WlanFreeMemory(networkList), networkList = NULL;
       }
    }
     
    void EnumerateInterface(HANDLE clientHandle)
    {
       WLAN_INTERFACE_INFO_LIST * interfaceList = NULL;
       DWORD lastError = WlanEnumInterfaces(clientHandle, NULL, &interfaceList);
     
       if(lastError != ERROR_SUCCESS)
       {
          DisplayError(_T("Error in the WlanEnumInterfaces() function call"), lastError);
       }
       else
       {
          DWORD item = 0;
          _tprintf(_T("There are %d Wifi interface\n"), interfaceList->dwNumberOfItems);
     
          for(; item != interfaceList->dwNumberOfItems; item++)
          {
             WLAN_INTERFACE_INFO * info = &interfaceList->InterfaceInfo[item];
             GUID * guid = &info->InterfaceGuid;
             LPOLESTR guid_str = NULL;
     
     
                _tprintf(_T("Interface %lu\n")
                         _T("\tThe Wifi interface GUID is [%ws]\n")
                         _T("\tThe Wifi interface description is [%ws]\n")
                         _T("\tThe Wifi interface state is [%s]\n"), 
                      item, guid_str, info->strInterfaceDescription, StateToString(info->isState));
     
                CoTaskMemFree(guid_str), guid_str = NULL;
     
     
             EnumerateNetwork(clientHandle, guid);
          }
     
          WlanFreeMemory(interfaceList), interfaceList = NULL;
       }
    }
    Mais lorsque je compile, j'ai systématiquement la même adresse MAC pour tout les points d'accès ce qui parait ridicule :/

Discussions similaires

  1. Afficher réseaux wifi dans une appli python
    Par helpy dans le forum Général Python
    Réponses: 2
    Dernier message: 31/05/2010, 11h09
  2. Générateur trafic dans réseaux Wifi
    Par Clopinet85 dans le forum Réseau
    Réponses: 2
    Dernier message: 02/05/2010, 16h39
  3. [réseaux wifi - nintendo DS]
    Par Aicha78 dans le forum Dépannage et Assistance
    Réponses: 1
    Dernier message: 31/03/2010, 10h54
  4. problème de détection de réseaux wifi
    Par Jasmine80 dans le forum Ubuntu
    Réponses: 2
    Dernier message: 21/07/2008, 18h36
  5. Réponses: 13
    Dernier message: 03/05/2007, 21h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo