Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get SSID
#7
Can you help to correct the code?

Macro Macro162
Code:
Copy      Help
;// Constantes para estados de interfaz WLAN
int wlan_interface_state_not_ready = 0
int wlan_interface_state_connected = 1
int wlan_interface_state_ad_hoc_network_formed = 2
int wlan_interface_state_disconnecting = 3
int wlan_interface_state_disconnected = 4
int wlan_interface_state_associating = 5
int wlan_interface_state_discovering = 6
int wlan_interface_state_authenticating = 7

;// Constantes para modo de conexión WLAN
int wlan_connection_mode_profile = 0
int wlan_connection_mode_temporary_profile = 1
int wlan_connection_mode_discovery_secure = 2

int wlan_connection_mode_discovery_unsecure = 3
int wlan_connection_mode_auto = 4
int wlan_connection_mode_invalid = 5

;// Estructura para SSID WiFi
type DOT11_SSID
,int'uSSIDLength
,byte'ucSSID[32]

;// Estructura para atributos de asociación WLAN
type WLAN_ASSOCIATION_ATTRIBUTES
,DOT11_SSID'dot11Ssid
,int'dot11BssType
,byte'dot11Bssid[6]
,int'dot11PhyType
,int'uDot11PhyIndex
,int'wlanSignalQuality
,int'ulRxRate
,int'ulTxRate

;// Estructura para atributos de seguridad WLAN
type WLAN_SECURITY_ATTRIBUTES
,int'bSecurityEnabled
,int'bOneXEnabled
,int'dot11AuthAlgorithm
,int'dot11CipherAlgorithm

;// Estructura para atributos de conexión WLAN
type WLAN_CONNECTION_ATTRIBUTES
,int'isState
,int'wlanConnectionMode
,str'strProfileName
,WLAN_ASSOCIATION_ATTRIBUTES'wlanAssociationAttributes
,WLAN_SECURITY_ATTRIBUTES'wlanSecurityAttributes

;// Estructura para información de interfaz WLAN
type WLAN_INTERFACE_INFO
,GUID'InterfaceGuid
,str'strInterfaceDescription
,int'isState

;// Estructura para lista de interfaces WLAN
type WLAN_INTERFACE_INFO_LIST
,int'NumberOfItems
,int'Index
,WLAN_INTERFACE_INFO'InterfaceInfo[1]

// =============================================
// DECLARACIONES DE FUNCIONES DLL
// =============================================

// Funciones para manejo de memoria
;dll msvcrt #memcpy int'dest int'src int'count

// Funciones de wlanapi.dll
dll wlanapi #WlanOpenHandle int'dwClientVersion int'reserved int*phNegotiatedVersion int*phClientHandle
dll wlanapi #WlanEnumInterfaces int'hClientHandle int'reserved int*ppInterfaceList
dll wlanapi #WlanQueryInterface int'hClientHandle int*pInterfaceGuid int'OpCode int'reserved int*pdwDataSize int*ppData int*pWlanOpcodeValueType
dll wlanapi #WlanCloseHandle int'hClientHandle int'reserved
dll wlanapi #WlanFreeMemory int'pMemory

// Funciones de iphlpapi.dll
type IP_ADDRESS_STRING !String[16]
type IP_ADDR_STRING IP_ADDR_STRING*Next IP_ADDRESS_STRING'IpAddress IP_ADDRESS_STRING'IpMask int'Context
type IP_ADAPTER_INFO IP_ADAPTER_INFO*Next int'ComboIndex !AdapterName[260] !Description[132] int'AddressLength !Address[8] int'Index int'Type int'DhcpEnabled IP_ADDR_STRING*CurrentIpAddress IP_ADDR_STRING'IpAddressList IP_ADDR_STRING'GatewayList IP_ADDR_STRING'DhcpServer int'HaveWins IP_ADDR_STRING'PrimaryWinsServer IP_ADDR_STRING'SecondaryWinsServer int'LeaseObtained int'LeaseExpires
dll iphlpapi #GetAdaptersInfo int*AdapterInfo int*SizePointer

// Funciones de kernel32.dll
dll kernel32 #LoadLibrary $lpFileName
dll kernel32 #FreeLibrary int'hModule

; ============================================================
; Macro para obtener e imprimir el SSID de la conexión WiFi
; ============================================================

; --- Obtener información de adaptadores de red ---
ARRAY(byte) AdapterInfo.create(16384)   ;; Buffer suficientemente grande
int dwBufLen = AdapterInfo.len
int pAdapterInfo = &AdapterInfo[0]

int dwStatus = GetAdaptersInfo(pAdapterInfo, &dwBufLen)
if(dwStatus != 0)
,end "Error al obtener información de adaptadores"

; --- Inicialización de variables para WLAN ---
int hClient = 0
int negotiatedVersion = 0
int pIfList = 0
str ssid = ""
int wlanapi_loaded = 0

; --- Verificar si wlanapi.dll está disponible ---
int hWlanApi = LoadLibrary("wlanapi.dll")
if hWlanApi != 0
,wlanapi_loaded = 1
,FreeLibrary(hWlanApi)
else
,end "wlanapi.dll no disponible"

if wlanapi_loaded = 1
,; --- Abrir handle de cliente WLAN ---
,int ret1 = WlanOpenHandle(2, 0, &negotiatedVersion, &hClient)
,if ret1 != 0
,,end "Error al abrir handle WLAN"
,
,; --- Enumerar interfaces WLAN ---
,ret1 = WlanEnumInterfaces(hClient, 0, &pIfList)
,if ret1 != 0
,,WlanCloseHandle(hClient, 0)
,,end "Error al enumerar interfaces WLAN"
,
,; --- Consultar atributos de conexión para la primera interfaz ---
,int pData = 0
,int dataSize = 0
,; Se utiliza el opcode 7 (WLAN_INTF_OPCODE_CURRENT_CONNECTION) para obtener los atributos actuales
,ret1 = WlanQueryInterface(hClient pIfList.InterfaceInfo[0].InterfaceGuid 7 0 &dataSize &pData 0)
,if ret1 != 0
,,WlanFreeMemory(pIfList)
,,WlanCloseHandle(hClient, 0)
,,end "Error al consultar atributos de conexión"
,
,; --- Convertir el SSID de arreglo de bytes a cadena ---
,int length = ((WLAN_CONNECTION_ATTRIBUTES*)pData).wlanAssociationAttributes.dot11Ssid.uSSIDLength
,int i
,for i 0 length-1
,,ssid = ssid + char(((WLAN_CONNECTION_ATTRIBUTES*)pData).wlanAssociationAttributes.dot11Ssid.ucSSID[i])
,
,; --- Imprimir el SSID ---
,out F"SSID: {ssid}"
,
,; --- Liberar memoria y cerrar el handle ---
,WlanFreeMemory(pData)
,WlanFreeMemory(pIfList)
,WlanCloseHandle(hClient, 0)
,


Messages In This Thread
Get SSID - by _pi - 07-30-2018, 05:32 PM
RE: Get SSID - by TheDane - 08-01-2018, 01:54 PM
RE: Get SSID - by _pi - 08-05-2018, 04:30 PM
RE: Get SSID - by Kevin - 08-05-2018, 09:07 PM
RE: Get SSID - by Kevin - 08-06-2018, 04:00 AM
RE: Get SSID - by _pi - 08-06-2018, 01:09 PM
RE: Get SSID - by Lucas - 04-01-2025, 05:20 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)