Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get SSID
#1
Hi,

how do i get the SSID when already connected to WLAN?
pi
#2
Hi __pi
- that rhymes Big Grin

I have been a stalker in this forum for too long, now it's time to pay back for all the help I have found in here..

I would find network info in the Windows Registry.
if your Windows is 64bit, you need the 64bit flag like this:

Code:
Copy      Help
str SSID
rget(SSID "SelectedWiFiProfile" "SOFTWARE\Microsoft\Windows\CurrentVersion\Control Panel\Settings\Network\Preferences" HKEY_LOCAL_MACHINE|HKEY_64BIT)
out SSID
#3
Thanks for you help, but unfortunatly the registry key has only the last SSID from the manually selected WLAN.
When WLAB connection is set to automatic connect, then the SSID will not saved into the key.
pi
#4
try this 

Function GetCurrentSSID
Code:
Copy      Help
str s ss
if(RunConsole2("NETSH WLAN SHOW INTERFACE" s)) end "failed"
if(findrx(s "   SSID .+"  0 1 ss)>0)
,ss.trim
,out ss 
else
,out s

@ Gintaras 
the actual command line is
NETSH WLAN SHOW INTERFACE | findstr /r "^....SSID"
Is there a way to do this in  RunConsole2  other than what i have done?
I couldn't get it to work directly with the full command in RunConsole2
it just ignored the findstr argument and just gave the results as if i sent NETSH WLAN SHOW INTERFACE
#5
nevermind figured it out
Function GetCurrentSSID2
Code:
Copy      Help
str s cl="cmd.exe /C NETSH WLAN SHOW INTERFACE | findstr /r ''^....SSID''"
RunConsole2 cl s
s.trim
out s
#6
Works fine.
Thanks!
pi
#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)
,


Forum Jump:


Users browsing this thread: 1 Guest(s)