Windows operatsioon süsteemi WiFi API: Difference between revisions
New page: Category:Traadita side alused |
No edit summary |
||
Line 1: | Line 1: | ||
[[Category:Traadita side alused]] | [[Category:Traadita side alused]] | ||
Kui teie oskate programmerida ja teil on Windows Vista või kõrgem operatsiooni süsteem, siis saate ligipääs “varjatud” infole. Selleks teil tuleb vahele toppida (Interop) üks windows library “wlanapi.dll”. Kogu vajalik info saab pärida siit: | |||
[DllImport("wlanapi.dll")] | |||
public static extern int WlanGetNetworkBssList( | |||
[In] IntPtr clientHandle, | |||
[In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid, | |||
[In] IntPtr dot11SsidInt, | |||
[In] Dot11BssType dot11BssType, | |||
[In] bool securityEnabled, | |||
IntPtr reservedPtr, | |||
[Out] out IntPtr wlanBssList | |||
); | |||
ja näite algorütm millega saab arvestada välja millist wifi kanalit võiks antud võrgus kasutada Access Pointi seadistamiseks: | |||
public List<int> AnalyzeResult() { | |||
string routerSSID = tbRouterSSID.Text.Trim(); | |||
if (routerSSID == string.Empty) routerSSID = null; | |||
int[] strengthes = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | |||
int[] counts = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | |||
foreach (WiFiNetwork wifiNetwork in NETWORKS) { | |||
if (wifiNetwork.Name != routerSSID) { | |||
strengthes[wifiNetwork.Channel - 1] += wifiNetwork.SignalStrength; | |||
counts[wifiNetwork.Channel - 1] += 1; | |||
} | |||
} | |||
int[] results = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | |||
int[] count_results = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | |||
for (int i = 0; i < 11; i++) { | |||
for (int j = -2; j <= 2; j++) { | |||
int o = i + j; | |||
if (o > -1 && o < 11) { | |||
int l = strengthes[o]; | |||
int c = counts[o]; | |||
if (l > 0) { | |||
results[i] += l; | |||
count_results[i] += c; | |||
} | |||
} | |||
} | |||
} | |||
for (int i = 0; i < 11; i++) { | |||
results[i] = results[i] * count_results[i]; | |||
} | |||
List<int> result = new List<int>(); | |||
int min = results.Min(); | |||
for (int i = 0; i < 11; i++) { | |||
if (results[i] == min) result.Add(i + 1); | |||
} | |||
return result; | |||
} | |||
'''Edukat wifi seadistamist!!!''' |
Revision as of 09:23, 6 May 2010
Kui teie oskate programmerida ja teil on Windows Vista või kõrgem operatsiooni süsteem, siis saate ligipääs “varjatud” infole. Selleks teil tuleb vahele toppida (Interop) üks windows library “wlanapi.dll”. Kogu vajalik info saab pärida siit:
[DllImport("wlanapi.dll")] public static extern int WlanGetNetworkBssList( [In] IntPtr clientHandle, [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid, [In] IntPtr dot11SsidInt, [In] Dot11BssType dot11BssType, [In] bool securityEnabled, IntPtr reservedPtr, [Out] out IntPtr wlanBssList );
ja näite algorütm millega saab arvestada välja millist wifi kanalit võiks antud võrgus kasutada Access Pointi seadistamiseks:
public List<int> AnalyzeResult() { string routerSSID = tbRouterSSID.Text.Trim(); if (routerSSID == string.Empty) routerSSID = null; int[] strengthes = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int[] counts = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
foreach (WiFiNetwork wifiNetwork in NETWORKS) { if (wifiNetwork.Name != routerSSID) { strengthes[wifiNetwork.Channel - 1] += wifiNetwork.SignalStrength; counts[wifiNetwork.Channel - 1] += 1; } }
int[] results = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int[] count_results = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
for (int i = 0; i < 11; i++) { for (int j = -2; j <= 2; j++) { int o = i + j; if (o > -1 && o < 11) { int l = strengthes[o]; int c = counts[o]; if (l > 0) { results[i] += l; count_results[i] += c; } } } }
for (int i = 0; i < 11; i++) { results[i] = results[i] * count_results[i]; }
List<int> result = new List<int>(); int min = results.Min(); for (int i = 0; i < 11; i++) { if (results[i] == min) result.Add(i + 1); }
return result; }
Edukat wifi seadistamist!!!