Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for missing access points in the list. #39 #36 #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions SimpleWifi/Wifi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -28,17 +30,23 @@ public Wifi()

foreach (var inte in _client.Interfaces)
inte.WlanNotification += inte_WlanNotification;

// Scan all interfaces
Scan();
}

/// <summary>
/// Returns a list over all available access points
/// </summary>
public List<AccessPoint> GetAccessPoints()
public List<AccessPoint> GetAccessPoints(bool bRescan = true)
{
List<AccessPoint> accessPoints = new List<AccessPoint>();
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);
Expand All @@ -63,6 +71,22 @@ public List<AccessPoint> GetAccessPoints()
return accessPoints;
}

/// <summary>
/// Rescan all wifi interfaces
/// </summary>
public void Scan()
{
foreach (WlanInterface wlanIface in _client.Interfaces)
{
try
{
wlanIface.Scan();
}
catch { }
}
_lastScanned = DateTime.Now;
}

/// <summary>
/// Disconnect all wifi interfaces
/// </summary>
Expand Down