public class Wlan { private static native int WiFi_Create(); private static native int WiFi_GetUsedAPI(); private static native int WiFi_CreateAPList(); // private static native int WiFi_getAPListSize(); private static native String WiFi_GetAPName(int ind); private static native byte[] WiFi_GetAPMAC(int ind); private static native int WiFi_GetAPRSSI(int ind); private static native int WiFi_InfrastructureMode(int ind); private static native void WiFi_Destroy(); private static int adapterListSize, apListSize; static { /* try { Runtime.getRuntime().exec("net stop \"Wireless Zero Configuration\""); //stops the WZC } catch(Exception ex) {} try { Thread.sleep(1000); } catch (Exception ex) {} */ System.load("C:/Users/admin/Desktop/10-4-2011/WlanDLL/WlanDLL/Wlan.dll"); //System.loadLibrary("Wlan.dll"); //loads the library adapterListSize = -1; apListSize = 0; } //calls function to create the wlanapi object, the list of Wi-Fi adapters, and returns its size public static int createAdapterList() { if (adapterListSize < 0) adapterListSize = WiFi_Create(); // System.out.println(adapterListSize); return adapterListSize; } //returns textual information on the used interface and the number of Wi-Fi adapters public static String getInfo() { String str; switch (adapterListSize) { case -1: str = "Unable to find a valid method for retrieving a list of network interfaces."; break; case 0: str = "No WiFi interfaces found."; break; case 1: str = "WiFi interface found."; break; default: str = "Found " + Integer.toString(adapterListSize) + " WiFi interfaces."; } if (adapterListSize >= 0) { switch (WiFi_GetUsedAPI()) { case -1: adapterListSize = -1; break; case 0: str = "Using (K)NetworkManager over D-BUS. " + str; break; case 1: str = "Using Wireless Zero Configuration (WZC) service (not recommended on WinXP). " + str; break; case 2: str = "Using Native Wifi API (do not use on WinXP). " + str; break; case 3: str = "Using NDIS User-Mode I/O (NDISUIO) driver. " + str; break; } } return str; } //calls the function to generate/update AP list and returns its size public static int createAPList() { if (adapterListSize < 1) { System.out.println(adapterListSize); apListSize = 0; return -1; } apListSize = WiFi_CreateAPList(); System.out.println("hi"+ apListSize); return apListSize; } //returns AP list size public static int getAPListSize() { // System.out.println("hi"); return apListSize; } //returns name of a particular AP from the list public static String getAPName(int ind) { if ((adapterListSize < 1) || (ind >= apListSize)) return "nnn"; return WiFi_GetAPName(ind); } //returns mac address of a particular AP from the list public static byte[] getAPMAC(int ind) { if ((adapterListSize < 1) || (ind >= apListSize)) return null; byte[] tmp = WiFi_GetAPMAC(ind); if (tmp.length < 6) System.out.println("Error getting MAC address."); return tmp; } //returns RSSI of a particular AP from the list public static int getAPRSSI(int ind) { if ((adapterListSize < 1) || (ind >= apListSize)) return -2002; int tmp = WiFi_GetAPRSSI(ind); //expected values are around -10..-100 if (tmp <= -1000) System.out.println("Error getting RSSI."); return tmp; } //returns type (InfrastructureMode) of a particular AP from the list //With NDISUIO and Native Wifi API: 0 = Independent (peer); 1 = Infrastructure (AP); 2 = AutoUnknown public static int getAPInfrastructureMode(int ind) { if ((adapterListSize < 1) || (ind >= apListSize)) return -1; return WiFi_InfrastructureMode(ind); } //calls the function which destroys the wlanapi object public static void destroy() { WiFi_Destroy(); adapterListSize = -1; apListSize = 0; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)