diff --git a/SimpleWifi/Wifi.cs b/SimpleWifi/Wifi.cs
index 89fccf9..afbd231 100644
--- a/SimpleWifi/Wifi.cs
+++ b/SimpleWifi/Wifi.cs
@@ -19,6 +19,8 @@ public class Wifi
private bool _isConnectionStatusSet = false;
public bool NoWifiAvailable = false;
+ private DateTime _lastScanned = DateTime.MinValue;
+
public Wifi()
{
_client = new WlanClient();
@@ -28,17 +30,23 @@ public Wifi()
foreach (var inte in _client.Interfaces)
inte.WlanNotification += inte_WlanNotification;
+
+ // Scan all interfaces
+ Scan();
}
///
/// Returns a list over all available access points
///
- public List GetAccessPoints()
+ public List GetAccessPoints(bool bRescan = true)
{
List accessPoints = new List();
if (_client.NoWifiAvailable)
return accessPoints;
-
+
+ if (bRescan && (DateTime.Now - _lastScanned > TimeSpan.FromSeconds(60)))
+ Scan();
+
foreach (WlanInterface wlanIface in _client.Interfaces)
{
WlanAvailableNetwork[] rawNetworks = wlanIface.GetAvailableNetworkList(0);
@@ -63,6 +71,22 @@ public List GetAccessPoints()
return accessPoints;
}
+ ///
+ /// Rescan all wifi interfaces
+ ///
+ public void Scan()
+ {
+ foreach (WlanInterface wlanIface in _client.Interfaces)
+ {
+ try
+ {
+ wlanIface.Scan();
+ }
+ catch { }
+ }
+ _lastScanned = DateTime.Now;
+ }
+
///
/// Disconnect all wifi interfaces
///