Click here to Skip to main content
15,894,289 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Wlan.java
C#
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;
    }
}


this only give wifi list in windows XP , not in windows7 how can i get output in windows7 ...
the wlan.dll, wlan.h file is there can any one help for windows 7..plz..
Posted
Updated 18-Apr-12 1:14am
v3
Comments
TorstenH. 18-Apr-12 1:23am    
I added several tags, because I guess those give a bitter chance to get an answer as this is a OS related and therefor MS related question.
Code-o-mat 18-Apr-12 6:34am    
Also tell us "how it does not give the list", does it give you an error? Does it create an empty list? Does it crash?
A side question: is there maybe a "bitness" difference between the XP and the Win7 system you tried? E.g. XP is 32 bit, Win7 is 64 bit. If yes, could that be the reason it works in one but not in the other?
Member 8054791 18-Apr-12 10:41am    
In win XP it give a list of wifi, but in Wind7 return 0

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900