Author Topic: Getting Raw Wifi Information (Windows)  (Read 2412 times)

0 Members and 2 Guests are viewing this topic.

Offline $Clone

  • Peasant
  • *
  • Posts: 86
  • Cookies: 5
  • $---Shadowalker---$
    • View Profile
Getting Raw Wifi Information (Windows)
« on: January 21, 2015, 08:04:22 pm »
Hey i started working on a windows c/c++ project and the first thing i wanted to do is try to learn as much as i can on the wifi network around me.I started by getting to know my wifi adapter all the way to the available networks.I quickly browsed msdn set of wifi functions and this is what i have so far:
Code: (C) [Select]

#ifndef UNICODE
#define UNICODE
#endif
//Define Unicode constant


#include <windows.h>
#include <wlanapi.h>  //Header for interfacing with wifi functions
#include <objbase.h>  //Need Function to help in converting GUID to a readable format
#include <wtypes.h>   //helps to deal with wide char
#include <stdio.h>
#include <stdlib.h>


// Need to link with Wlanapi.lib and Ole32.lib
#pragma comment(lib, "wlanapi.lib")
#pragma comment(lib, "ole32.lib")


int wmain()
{


    // Declare and initialize variables.


    HANDLE hClient = NULL;
    DWORD dwMaxClient = 2;   //   
    DWORD dwCurVersion = 0;
    DWORD dwResult = 0;
    int iRet = 0;
   
    WCHAR GuidString[40] = {0};
     
    int i;
   const GUID*ptr;
   


    /* variables used for WlanEnumInterfaces  */
   
    PWLAN_INTERFACE_INFO_LIST EnumList = NULL;
    PWLAN_INTERFACE_INFO EnumInfo = NULL;
   /*variables used for geting interface capability*/
   PWLAN_INTERFACE_CAPABILITY pGetCap=NULL;
   /*variables used to get SSID and networks available*/
   PWLAN_AVAILABLE_NETWORK_LIST netwklist=NULL;
   PWLAN_AVAILABLE_NETWORK Netlist=NULL;
   PDOT11_SSID ssid=NULL;


   //Get Handle to Wlan
dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
    if (dwResult != ERROR_SUCCESS)  {
        wprintf(L"WlanOpenHandle failed with error: %u\n", dwResult);
        // FormatMessage can be used to find out why the function failed
        return 1;
    }
   
    dwResult = WlanEnumInterfaces(hClient, NULL, &EnumList);
    if (dwResult != ERROR_SUCCESS)  {
        wprintf(L"WlanEnumInterfaces failed with error: %u\n", dwResult);
       
        return 1;
    }
    else {
      wprintf(L"Enumerated Devices in the Computer:\n");
      wprintf(L"--------------------------------------------------------------\n");
      wprintf(L"--------------------------------------------------------------\n");
        wprintf(L"Num Entries: %lu\n", EnumList->dwNumberOfItems);
        wprintf(L"Current Index: %lu\n", EnumList->dwIndex);
        for (i = 0; i < (int) EnumList->dwNumberOfItems; i++) {
            EnumInfo = (WLAN_INTERFACE_INFO *) &EnumList->InterfaceInfo;
            wprintf(L"Interface Index[%d]: %lu\n", i, i);
            iRet = StringFromGUID2(EnumInfo->InterfaceGuid, (LPOLESTR) &GuidString, 39); 
            if (iRet == 0)
                wprintf(L"StringFromGUID2 failed\n");
            else {
                wprintf(L"InterfaceGUID[%d]: %ws\n",i, GuidString);
            }   
            wprintf(L"Interface Description[%d]: %ws", i,
                EnumInfo->strInterfaceDescription);
            wprintf(L"\n");
            wprintf(L"Interface State[%d]:", i);
            switch (EnumInfo->isState) {
            case wlan_interface_state_not_ready:
                wprintf(L"Not ready\n");
                break;
            case wlan_interface_state_connected:
                wprintf(L"Connected\n");
                break;
            case wlan_interface_state_ad_hoc_network_formed:
                wprintf(L"First node in a ad hoc network\n");
                break;
            case wlan_interface_state_disconnecting:
                wprintf(L"Disconnecting\n");
                break;
            case wlan_interface_state_disconnected:
                wprintf(L"Not connected\n");
                break;
            case wlan_interface_state_associating:
                wprintf(L"Attempting to associate with a network\n");
                break;
            case wlan_interface_state_discovering:
                wprintf(L"Auto configuration is discovering settings for the network\n");
                break;
            case wlan_interface_state_authenticating:
                wprintf(L"In process of authenticating\n");
                break;
            default:
                wprintf(L"Unknown state %ld\n", EnumInfo->isState);
                break;
         }
         wprintf(L"--------------------------------------------------------------\n");
         wprintf(L"--------------------------------------------------------------\n");
         wprintf(L"Getting Interface Capabilities info\n");
         wprintf(L"--------------------------------------------------------------\n");
         wprintf(L"--------------------------------------------------------------\n");


              ptr=&EnumInfo->InterfaceGuid;
            dwResult=WlanGetInterfaceCapability(hClient,ptr,NULL,&pGetCap);
            if(dwResult!=ERROR_SUCCESS)
            {
               wprintf(L"Error %d while getting Interface capability!\n",dwResult);
            }
            else{
               wprintf(L"InterFace Type:%d\n",pGetCap->interfaceType);
               wprintf(L"Support for 802.11d:%s\n",pGetCap->bDot11DSupported);
               wprintf(L"Maximum size of the SSID list:%d\n",pGetCap->dwMaxDesiredSsidListSize);
               wprintf(L"maximum size of the basic service set:%d\n",pGetCap->dwMaxDesiredBssidListSize);
               wprintf(L"number of supported PHY types:%d\n",pGetCap->dwNumberOfSupportedPhys);
            }
            wprintf(L"--------------------------------------------------------------\n");
              wprintf(L"--------------------------------------------------------------\n");
            wprintf(L"Wifi Scan information\n");
            wprintf(L"--------------------------------------------------------------\n");
              wprintf(L"--------------------------------------------------------------\n");
           
            dwResult=WlanScan(hClient,ptr,ssid,0,0);
            if(dwResult!=ERROR_SUCCESS)
               wprintf(L"Error will Scanning for networks!\n");
            else{
               dwResult=WlanGetAvailableNetworkList(hClient,ptr,0x00000002,NULL,&netwklist);
               if(dwResult!=ERROR_SUCCESS)
               wprintf(L"Error get network list check param.\n");
               else{
                  if(netwklist->dwNumberOfItems>0)
                  {
                  wprintf(L"Number of a vailable wifi networks:%d\n",netwklist->dwNumberOfItems);
                  for(unsigned int i=0;i<netwklist->dwNumberOfItems;i++)
                  {
                     Netlist=(WLAN_AVAILABLE_NETWORK *)&netwklist->Network;
                     wprintf(L"Network Details %d:\n",i);
                      wprintf(L"--------------------------------------------------------------\n");
                     wprintf(L"Network Name:%s\n",Netlist->strProfileName);
                     wprintf(L"Number of BSSIDs in the network:%d\n",Netlist->uNumberOfBssids);
                     //Not that you can create a switch,fuction detail the reason why WLAN is not connectable.
                     //check WLAN_REASON_CODE.
                     if(Netlist->bNetworkConnectable==1 && Netlist->bSecurityEnabled==1)
                        wprintf(L"Connected to Network and Security is enabled.\n");
                     else if(Netlist->bNetworkConnectable ==1 && Netlist->bSecurityEnabled!=1)
                        wprintf(L"Connected to network and Security disabled.\n");
                     else
                        wprintf(L"Not connected!\n");


                     wprintf(L"Signal Quality:%d\n",Netlist->wlanSignalQuality);
                     wprintf(L"Security Algorithm:%d\tneed more formating\n",Netlist->dot11DefaultAuthAlgorithm);
                     wprintf(L"Cyphier Algorithm:%d\tneed more formating\n",Netlist->dot11DefaultCipherAlgorithm);
                      wprintf(L"--------------------------------------------------------------\n");
                  }
                  }
                  else
                     wprintf(L"No Wifi Networks Available\n");
                 
               }


         }
wprintf(L"\n");
wprintf(L"-------------------------------------------------------\n");
wprintf(L"-------------------------------------------------------\n");
wprintf(L"End!\n");
          }
    }


    if (EnumList != NULL) {
        WlanFreeMemory(EnumList);
        EnumList = NULL;
    }
   getchar();
    return 0;
}




try it out! 

« Last Edit: January 21, 2015, 08:05:43 pm by $Clone »

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
Re: Getting Raw Wifi Information (Windows)
« Reply #1 on: January 22, 2015, 11:03:34 am »
If it is a project the choose one, C or C++. That crap is for when we are doing tuts or something. If you are coding in it, the be clear to choose.
You sure are doing alot of printing. My advice is that divide the different tasks into functions then return from those functions to the main function that will do the IO mainly.
I am not on my PC so that is what i will comment for now.
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]

Offline $Clone

  • Peasant
  • *
  • Posts: 86
  • Cookies: 5
  • $---Shadowalker---$
    • View Profile
Re: Getting Raw Wifi Information (Windows)
« Reply #2 on: January 22, 2015, 03:58:53 pm »
 :o ..Kenjoe41 maybe you should tweak the code and show precisely what you mean.....I get that it has alot of printing and at the time i didn't want to bundle every thing in functions i was simply getting to know wlan functions  :D .... i will use C for my project.

Offline HTH

  • Official EZ Slut
  • Administrator
  • Knight
  • *
  • Posts: 395
  • Cookies: 158
  • EZ Titan
    • View Profile
Re: Getting Raw Wifi Information (Windows)
« Reply #3 on: January 22, 2015, 11:40:52 pm »
I am in a hurry with IRL things so I cannot actually tweak the code but as for the C/C++ thing he was simply saying when you share code be sure to specify which language you used. As much as they ar interchangeable in many ways they ARE different languages.


I quickly skimmed this code and unless I missed something funky I believe this is only C code, but it is very possible I missed something as i basically scrolled down looking for << lol.
<ande> HTH is love, HTH is life
<TurboBorland> hth is the only person on this server I can say would successfully spitefuck peoples women

Offline $Clone

  • Peasant
  • *
  • Posts: 86
  • Cookies: 5
  • $---Shadowalker---$
    • View Profile
Re: Getting Raw Wifi Information (Windows)
« Reply #4 on: January 22, 2015, 11:56:36 pm »
@HTH ....The code is in C....i thought the C  <headers> where enough to give a discription...anyway  :)

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
Re: Getting Raw Wifi Information (Windows)
« Reply #5 on: January 23, 2015, 09:06:32 am »
@HTH ....The code is in C....i thought the C  <headers> where enough to give a discription...anyway  :)
I can actually do #include <stdio.h> rather than #include <cstdio> and all will be fine. It is quite a practice for those who have a C background.

Anyway just keep on learning. If you interface with the Linux API, then you could roll a cross-platform library as we know we sure lack one good one out there. Mark you, those function calls might not work for some network cards and not cross windows distributions. So you have some work to do here if you want to stick with it. Remember when you want to learn it, don't skim through it, explore it thoroughly.
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]

Offline $Clone

  • Peasant
  • *
  • Posts: 86
  • Cookies: 5
  • $---Shadowalker---$
    • View Profile
Re: Getting Raw Wifi Information (Windows)
« Reply #6 on: January 23, 2015, 10:39:00 am »
I can actually do #include <stdio.h> rather than #include <cstdio> and all will be fine. It is quite a practice for those who have a C background.

Anyway just keep on learning. If you interface with the Linux API, then you could roll a cross-platform library as we know we sure lack one good one out there. Mark you, those function calls might not work for some network cards and not cross windows distributions. So you have some work to do here if you want to stick with it. Remember when you want to learn it, don't skim through it, explore it thoroughly.
Working on it!