Hola, he buscado por internet y he encontrado este codigo un programador llamado RAGE.
Inicialmente era codigo C++ para consola pero lo he adaptado para un TForm con un Memo1 y un TButton para actualizar la deteccion de redes wifi
aqui tenéis el código fuente..... ecfisa, si ves que puedes mejorarlo con alguna caracteristica añadida (o alguno de vosotros) os propongo que vayamos desarrollando entre todos unas cuantas mejoras con el fin de aprender entre todos un poco sobre la programacion de Wifi Adapters y esas cosas
un saludo
Código PHP:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma comment(lib, "wlanapi.lib")
#include <stdio.h>
#include <windows.h>
#include <wlanapi.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
bool bWait = false;
void DETECTA_REDES(void);
VOID WlanNotification(WLAN_NOTIFICATION_DATA *wlanNotifData,VOID *p);
bool IsVistaOrHigher(void);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
/*
* WlanScan - by RAGE
*
* Coded while blasting Doomsday Machine by Arch Enemy.
*
* Rip the code if you want, just dont use it in a pussy project
*/
void DETECTA_REDES(void)
{
HANDLE hWlan = NULL;
DWORD dwError = 0;
DWORD dwSupportedVersion = 0;
DWORD dwClientVersion = (IsVistaOrHigher() ? 2 : 1);
GUID guidInterface; ZeroMemory(&guidInterface, sizeof(GUID));
WLAN_INTERFACE_INFO_LIST *wlanInterfaceList = (WLAN_INTERFACE_INFO_LIST*)WlanAllocateMemory(sizeof(WLAN_INTERFACE_INFO_LIST));
ZeroMemory(wlanInterfaceList, sizeof(WLAN_INTERFACE_INFO_LIST));
WLAN_AVAILABLE_NETWORK_LIST *wlanNetworkList = (WLAN_AVAILABLE_NETWORK_LIST*)WlanAllocateMemory(sizeof(WLAN_AVAILABLE_NETWORK_LIST));
ZeroMemory(wlanNetworkList, sizeof(WLAN_AVAILABLE_NETWORK_LIST));
try
{
if(dwError = WlanOpenHandle(dwClientVersion, NULL, &dwSupportedVersion, &hWlan) != ERROR_SUCCESS)
throw("[x] Unable access wireless interface");
if(dwError = WlanEnumInterfaces(hWlan, NULL, &wlanInterfaceList) != ERROR_SUCCESS)
throw("[x] Unable to enum wireless interfaces");
AnsiString p = wlanInterfaceList->InterfaceInfo[0].strInterfaceDescription;
Form1->Memo1->Lines->Add(p);
if(dwError = wlanInterfaceList->InterfaceInfo[0].isState != wlan_interface_state_not_ready)
{
if(wlanInterfaceList->dwNumberOfItems > 1)
{
// TODO: Add processing for multiple wireless cards here
Form1->Memo1->Lines->Add("[!] Detected multiple wireless adapters, using default\n");
guidInterface = wlanInterfaceList->InterfaceInfo[0].InterfaceGuid;
}
else
{
guidInterface = wlanInterfaceList->InterfaceInfo[0].InterfaceGuid;
}
}
else
throw("[x] Default wireless adapter disabled");
DWORD dwPrevNotif = 0;
// Scan takes awhile so we need to register a callback
if(dwError = WlanRegisterNotification(hWlan, WLAN_NOTIFICATION_SOURCE_ACM, TRUE,
(WLAN_NOTIFICATION_CALLBACK)WlanNotification, NULL, NULL, &dwPrevNotif) != ERROR_SUCCESS)
throw("[x] Unable to register for notifications");
Form1->Memo1->Lines->Add("[i] Scanning for nearby networks...\n");
if(dwError = WlanScan(hWlan, &guidInterface, NULL, NULL, NULL) != ERROR_SUCCESS)
throw("[x] Scan failed, check adapter is enabled");
// Yawn...
while(bWait)
Sleep(100);
// Unregister callback, don't care if it succeeds or not
WlanRegisterNotification(hWlan, WLAN_NOTIFICATION_SOURCE_NONE, TRUE, NULL, NULL, NULL, &dwPrevNotif);
if(dwError = WlanGetAvailableNetworkList(hWlan, &guidInterface, NULL, NULL, &wlanNetworkList) != ERROR_SUCCESS)
throw("[x] Unable to obtain network list");
for(unsigned int i = 0; i < wlanNetworkList->dwNumberOfItems; i++)
{
p = "";
unsigned char *pp;
pp = wlanNetworkList->Network[i].dot11Ssid.ucSSID;
Form1->Memo1->Lines->Add(AnsiString((char *)pp));
p = wlanNetworkList->Network[i].wlanSignalQuality;
Form1->Memo1->Lines->Add(p);
switch(wlanNetworkList->Network[i].dot11DefaultAuthAlgorithm)
{
case DOT11_AUTH_ALGO_80211_OPEN:
case DOT11_AUTH_ALGO_80211_SHARED_KEY:
Form1->Memo1->Lines->Add("SECURITY: WEP");
break;
case DOT11_AUTH_ALGO_WPA:
case DOT11_AUTH_ALGO_WPA_PSK:
case DOT11_AUTH_ALGO_WPA_NONE:
Form1->Memo1->Lines->Add("SECURITY: WPA");
break;
case DOT11_AUTH_ALGO_RSNA:
case DOT11_AUTH_ALGO_RSNA_PSK:
Form1->Memo1->Lines->Add("SECURITY: WPA2");
break;
default:
Form1->Memo1->Lines->Add("SECURITY: UNKNOWN");
break;
}
Form1->Memo1->Lines->Add("-----------------------");
}
}
catch(char *szError)
{
Form1->Memo1->Lines->Add("ERROR:: ");
Form1->Memo1->Lines->Add(szError);
}
if(wlanNetworkList)
WlanFreeMemory(wlanNetworkList);
if(wlanInterfaceList)
WlanFreeMemory(wlanInterfaceList);
if(hWlan)
WlanCloseHandle(hWlan, NULL);
//return dwError;
}
VOID WlanNotification(WLAN_NOTIFICATION_DATA *wlanNotifData,VOID *p)
{
if(wlanNotifData->NotificationCode == wlan_notification_acm_scan_complete)
{
bWait = false;
}
else if(wlanNotifData->NotificationCode == wlan_notification_acm_scan_fail)
{
printf("Scanning failed with error: %x\n", wlanNotifData->pData);
bWait = false;
}
}
bool IsVistaOrHigher(void)
{
OSVERSIONINFO osVersion; ZeroMemory(&osVersion, sizeof(OSVERSIONINFO));
osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(!GetVersionEx(&osVersion))
return false;
if(osVersion.dwMajorVersion >= 6)
return true;
return false;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Memo1->Lines->Clear();
DETECTA_REDES();
}
//---------------------------------------------------------------------------