Ver Mensaje Individual
  #1  
Antiguo 31-03-2017
Snaked Snaked is offline
Baneado
NULL
 
Registrado: sep 2016
Posts: 102
Reputación: 0
Snaked Va por buen camino
Cool Deteccion de redes Wifi (muestra nombre, encriptacion y señal)

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(TComponentOwner)
    : 
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() ? 1);

    
GUID guidInterfaceZeroMemory(&guidInterfacesizeof(GUID));

    
WLAN_INTERFACE_INFO_LIST *wlanInterfaceList = (WLAN_INTERFACE_INFO_LIST*)WlanAllocateMemory(sizeof(WLAN_INTERFACE_INFO_LIST));
    
ZeroMemory(wlanInterfaceListsizeof(WLAN_INTERFACE_INFO_LIST));

    
WLAN_AVAILABLE_NETWORK_LIST *wlanNetworkList = (WLAN_AVAILABLE_NETWORK_LIST*)WlanAllocateMemory(sizeof(WLAN_AVAILABLE_NETWORK_LIST));
    
ZeroMemory(wlanNetworkListsizeof(WLAN_AVAILABLE_NETWORK_LIST));

    try
    {
        if(
dwError WlanOpenHandle(dwClientVersionNULL, &dwSupportedVersion, &hWlan) != ERROR_SUCCESS)
            throw(
"[x] Unable access wireless interface");

        if(
dwError WlanEnumInterfaces(hWlanNULL, &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(hWlanWLAN_NOTIFICATION_SOURCE_ACMTRUE,
          (
WLAN_NOTIFICATION_CALLBACK)WlanNotificationNULLNULL, &dwPrevNotif) != ERROR_SUCCESS)
            throw(
"[x] Unable to register for notifications");

        
Form1->Memo1->Lines->Add("[i] Scanning for nearby networks...\n");
        if(
dwError WlanScan(hWlan, &guidInterfaceNULLNULLNULL) != 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(hWlanWLAN_NOTIFICATION_SOURCE_NONETRUENULLNULLNULL, &dwPrevNotif);

        if(
dwError WlanGetAvailableNetworkList(hWlan, &guidInterfaceNULLNULL, &wlanNetworkList) != ERROR_SUCCESS)
            throw(
"[x] Unable to obtain network list");

        for(
unsigned int i 0wlanNetworkList->dwNumberOfItemsi++)
        {

            
"";
            
unsigned char *pp;
            
pp wlanNetworkList->Network[i].dot11Ssid.ucSSID;
                
Form1->Memo1->Lines->Add(AnsiString((char *)pp));
            
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(hWlanNULL);

    
//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 osVersionZeroMemory(&osVersionsizeof(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();
}
//--------------------------------------------------------------------------- 
Responder Con Cita