public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. lblHeader.Font = UIFont.FromName("SourceSansPro-Light", 48f); lblSsid.Font = UIFont.FromName("SourceSansPro-Light", 24f); lblMac.Font = UIFont.FromName("SourceSansPro-Light", 24f); btnConnect.Font = UIFont.FromName("SourceSansPro-Light", 24f); btnLogFiles.Font = UIFont.FromName("SourceSansPro-Light", 24f); btnHelp.Font = UIFont.FromName("SourceSansPro-Light", 24f); lblFooter.Font = UIFont.FromName("SourceSansPro-Light", 14f); String[] interfaces; CaptiveNetwork.TryGetSupportedInterfaces(out interfaces); if (interfaces != null && interfaces.Length >= 1) { NSDictionary dict; CaptiveNetwork.TryCopyCurrentNetworkInfo(interfaces[0], out dict); if (dict != null) { var bssid = (NSString)dict[CaptiveNetwork.NetworkInfoKeyBSSID]; var ssid = (NSString)dict[CaptiveNetwork.NetworkInfoKeySSID]; if (ssid.ToString().ToLower().Contains("rasp") || ssid.ToString().ToLower().Contains("rasp")) { lblSsid.Text = "SSID: " + ssid.ToString(); lblMac.Text = "MAC: " + bssid.ToString(); btnConnect.SetTitle("Connect", UIControlState.Normal); btnConnect.Enabled = true; } } } }
public WifiInfo GetCurrentWifiInfo() { _semaphore.Wait(); var wifiInfo = new WifiInfo(); try { NSDictionary dict; var status = CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out dict); if (status == StatusCode.OK) { var bssid = dict[CaptiveNetwork.NetworkInfoKeyBSSID]; var ssid = dict[CaptiveNetwork.NetworkInfoKeySSID]; wifiInfo.Ssid = ssid.ToString(); wifiInfo.Bssid = bssid.ToString(); } } catch (EntryPointNotFoundException) { // running on sim... wifiInfo.Ssid = "Simulator"; wifiInfo.Bssid = "Simulator"; } finally { _semaphore.Release(); } return(wifiInfo); }
public void TryCopyCurrentNetworkInfo() { NSDictionary dict; StatusCode status; #if __TVOS__ Assert.Throws <NotSupportedException> (() => { status = CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out dict); }); #else status = CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out dict); // No network, ignore test if (status == StatusCode.NoKey) { return; } Assert.AreEqual(StatusCode.OK, status, "Status"); // To get a non-null dictionary back, starting in iOS 12, we must (https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo) // * Use core location, and request (and get) authorization to use location information // * Add the 'com.apple.developer.networking.wifi-info' entitlement // We're not using custom entitlements when building for device, which means that we can't make this work at the moment. // So just assert that we get null if running on iOS 12+. if (TestRuntime.CheckXcodeVersion(10, 0)) { Assert.IsNull(dict, "Dictionary"); } else { Assert.IsNotNull(dict, "Dictionary"); } #endif }
public void TryCopyCurrentNetworkInfo() { NSDictionary dict; StatusCode status; #if __TVOS__ Assert.Throws <NotSupportedException> (() => { status = CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out dict); }); #else status = CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out dict); // No network, ignore test if (status == StatusCode.NoKey) { return; } Assert.AreEqual(StatusCode.OK, status, "Status"); // It's quite complex to figure out whether we should get a dictionary back or not. // References: // * https://github.com/xamarin/xamarin-macios/commit/24331f35dd67d19f3ed9aca7b8b21827ce0823c0 // * https://github.com/xamarin/xamarin-macios/issues/11504 // * https://github.com/xamarin/xamarin-macios/issues/12278 // * https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo // So don't assert anything about the dictionary. #endif }
public Task <IEnumerable <WifiInfo> > GetAllWifiInfoAsync( CancellationToken token = new CancellationToken()) { var tcs = new TaskCompletionSource <IEnumerable <WifiInfo> >(); _semaphore.Wait(token); Task.Run(() => { var wifiInfo = new List <WifiInfo>(); var status = CaptiveNetwork.TryGetSupportedInterfaces(out string[] supportedInterfaces); if (status == StatusCode.OK && supportedInterfaces != null) { foreach (var @interface in supportedInterfaces) { CaptiveNetwork.TryCopyCurrentNetworkInfo(@interface, out NSDictionary dict); var bssid = dict[CaptiveNetwork.NetworkInfoKeyBSSID]; var ssid = dict[CaptiveNetwork.NetworkInfoKeySSID]; wifiInfo.Add(new WifiInfo { Bssid = bssid.ToString(), Ssid = ssid.ToString() }); } } tcs.TrySetResult(wifiInfo); _semaphore.Release(); }, token); return(tcs.Task); }
public void GetSupportedInterfaces() { if (Runtime.Arch == Arch.SIMULATOR) { if (RunningOnSnowLeopard) { Assert.Inconclusive("This test crash on the simulator with Snow Leopard"); } if (TestRuntime.CheckSystemAndSDKVersion(6, 0)) { Assert.Inconclusive("This test crash on the iOS 6 simulator with Lion"); } } string [] interfaces = CaptiveNetwork.GetSupportedInterfaces(); if (Runtime.Arch == Arch.SIMULATOR) { // we can't assume much about the computer running the simulator Assert.NotNull(interfaces, "GetSupportedInterfaces"); } else { Assert.That(interfaces.Length, Is.EqualTo(1), "1"); Assert.That(interfaces [0], Is.EqualTo("en0"), "en0"); } }
public async Task ShowCurrentWifiInformation() { await Geolocation.GetLocationAsync(); //return null pour des simulateurs var result = CaptiveNetwork.TryGetSupportedInterfaces(out var supportedInterfaces); if (result == StatusCode.OK && supportedInterfaces != null) { foreach (var r in supportedInterfaces) { Console.WriteLine(r); var netResult = CaptiveNetwork.TryCopyCurrentNetworkInfo(r, out var networkInfo); if (netResult == StatusCode.OK && networkInfo != null) { foreach (var kvp in networkInfo) { Console.WriteLine($"{kvp.Key} {kvp.Value}"); } } else { Console.WriteLine(netResult); } } } else { Console.WriteLine(result); } }
public string GetNetworkName() { String[] interfaces; CaptiveNetwork.TryGetSupportedInterfaces(out interfaces); if (interfaces != null && interfaces.Length >= 1) { NSDictionary dict; CaptiveNetwork.TryCopyCurrentNetworkInfo(interfaces[0], out dict); if (dict != null) { var bssid = (NSString)dict[CaptiveNetwork.NetworkInfoKeyBSSID]; var ssid = (NSString)dict[CaptiveNetwork.NetworkInfoKeySSID]; if (!String.IsNullOrEmpty(ssid)) { return(ssid); } if (!String.IsNullOrEmpty(bssid)) { return(bssid); } } } return("Not Connected"); }
public void MarkPortalOffline_Null() { #if __TVOS__ Assert.Throws <NotSupportedException> (() => CaptiveNetwork.MarkPortalOffline(null)); #else Assert.Throws <ArgumentNullException> (() => CaptiveNetwork.MarkPortalOffline(null)); #endif }
public void SetSupportedSSIDs_Null() { #if __TVOS__ Assert.Throws <NotSupportedException> (() => CaptiveNetwork.SetSupportedSSIDs(null)); #else Assert.Throws <ArgumentNullException> (() => CaptiveNetwork.SetSupportedSSIDs(null)); #endif }
public void MarkPortalOffline() { TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 8, throwIfOtherPlatform: false); #if __TVOS__ Assert.Throws <NotSupportedException> (() => CaptiveNetwork.MarkPortalOffline("xamxam")); #else Assert.False(CaptiveNetwork.MarkPortalOffline("xamxam")); #endif }
public void TryCopyCurrentNetworkInfo_Null() { NSDictionary dict; #if __TVOS__ Assert.Throws <NotSupportedException> (() => CaptiveNetwork.TryCopyCurrentNetworkInfo(null, out dict)); #else Assert.Throws <ArgumentNullException> (() => CaptiveNetwork.TryCopyCurrentNetworkInfo(null, out dict)); #endif }
protected override IEnumerable <Datum> Poll(CancellationToken cancellationToken) { NSDictionary networkInfo; string bssid = null; if (CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out networkInfo) != StatusCode.NoKey && networkInfo != null) { bssid = networkInfo[CaptiveNetwork.NetworkInfoKeyBSSID].ToString(); } return(new Datum[] { new WlanDatum(DateTimeOffset.UtcNow, bssid) }); }
protected override Task <List <Datum> > PollAsync(CancellationToken cancellationToken) { NSDictionary networkInfo; string bssid = null; if (CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out networkInfo) != StatusCode.NoKey && networkInfo != null) { bssid = networkInfo[CaptiveNetwork.NetworkInfoKeyBSSID].ToString(); } return(Task.FromResult(new Datum[] { new WlanDatum(DateTimeOffset.UtcNow, bssid) }.ToList())); }
public string GetCurrentWifiSSID() { NSDictionary nsDictionary; CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out nsDictionary); if (nsDictionary?[CaptiveNetwork.NetworkInfoKeySSID] == null) { return(string.Empty); } return(nsDictionary[CaptiveNetwork.NetworkInfoKeySSID].ToString()); }
protected override IEnumerable <Datum> Poll(CancellationToken cancellationToken) { NSDictionary networkInfo; if (CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out networkInfo) == StatusCode.NoKey || networkInfo == null) { return new Datum[] { } } ; return(new Datum[] { new WlanDatum(DateTimeOffset.UtcNow, networkInfo[CaptiveNetwork.NetworkInfoKeyBSSID].ToString()) }); } }
public void SetSupportedSSIDs() { TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 8, throwIfOtherPlatform: false); #if MONOMAC bool supported = true; #else // that API is deprecated in iOS9 - and it might be why it returns false (or not) bool supported = !TestRuntime.CheckXcodeVersion(7, 0); #endif Assert.That(CaptiveNetwork.SetSupportedSSIDs(new string [2] { "one", "two" }), Is.EqualTo(supported), "set"); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. Task.Run(() => { string[] supportedInterfaces; if (CaptiveNetwork.TryGetSupportedInterfaces(out supportedInterfaces) == StatusCode.OK && supportedInterfaces != null && supportedInterfaces.Length > 0) { foreach (var si in supportedInterfaces) { NSDictionary networkInfo; if (CaptiveNetwork.TryCopyCurrentNetworkInfo(si, out networkInfo) == StatusCode.OK) { if (networkInfo.Count > 0) { NSObject value; if (networkInfo.TryGetValue(CaptiveNetwork.NetworkInfoKeySSID, out value)) { BeginInvokeOnMainThread(() => { lblSsid.Text = string.Format("SSID: {0}", value); }); } if (networkInfo.TryGetValue(CaptiveNetwork.NetworkInfoKeyBSSID, out value)) { BeginInvokeOnMainThread(() => { lblBssid.Text = string.Format("BSSID: {0}", value); }); } if (networkInfo.TryGetValue(CaptiveNetwork.NetworkInfoKeySSIDData, out value)) { BeginInvokeOnMainThread(() => { lblSsidData.Text = string.Format("SSID Data: {0}", value); }); } } } } } else { BeginInvokeOnMainThread(() => { var alert = new UIAlertView("Error", "Cannot get network info!", null, "Ok"); alert.Show(); }); } }); }
public void SetSupportedSSIDs() { if (Runtime.Arch == Arch.SIMULATOR) { if (RunningOnSnowLeopard) { Assert.Inconclusive("This test crash on the simulator with Snow Leopard"); } } // that API is deprecated in iOS9 - and it might be why it returns false (or not) bool supported = !UIDevice.CurrentDevice.CheckSystemVersion(9, 0); Assert.That(CaptiveNetwork.SetSupportedSSIDs(new string [2] { "one", "two" }), Is.EqualTo(supported), "set"); }
protected override void Refresh() { var profiles = Connectivity.ConnectionProfiles; if (profiles.Contains(ConnectionProfile.Cellular)) { Status = NetStatus.Wwan; } else if (profiles.Contains(ConnectionProfile.WiFi)) { Status = NetStatus.Wlan; try { CheckStatus(CaptiveNetwork.TryGetSupportedInterfaces(out string[] interfaces)); if (interfaces.Length == 0) { Ssid = string.Empty; } else { CheckStatus(CaptiveNetwork.TryCopyCurrentNetworkInfo(interfaces[0], out NSDictionary dict)); using (dict) { if (dict.TryGetValue(CaptiveNetwork.NetworkInfoKeySSID, out NSObject ssid)) { Status = NetStatus.Wlan; Ssid = ssid.ToString(); } } } } catch (Exception ex) { Debug.WriteLine(ex); Ssid = string.Empty; } } else if (profiles.Contains(ConnectionProfile.Ethernet)) { Status = NetStatus.Lan; } else { Status = NetStatus.Unknown; } }
public void TryCopyCurrentNetworkInfo() { if (Runtime.Arch == Arch.SIMULATOR) { #if __IOS__ if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 6, 0)) { Assert.Inconclusive("This test throws EntryPointNotFoundException on the iOS 6 simulator with Lion"); } #endif } NSDictionary dict; var status = CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out dict); // No network, ignore test if (status == StatusCode.NoKey) { return; } Assert.AreEqual(StatusCode.OK, status, "Status"); #if __TVOS__ Assert.IsNull(dict, "Dictionary"); // null? return; #endif if ((dict == null) && (Runtime.Arch == Arch.DEVICE) && TestRuntime.CheckSystemVersion(PlatformName.iOS, 9, 0)) { Assert.Ignore("null on iOS9 devices - CaptiveNetwork is being deprecated ?!?"); } if (dict.Count == 3) { Assert.NotNull(dict [CaptiveNetwork.NetworkInfoKeyBSSID], "NetworkInfoKeyBSSID"); Assert.NotNull(dict [CaptiveNetwork.NetworkInfoKeySSID], "NetworkInfoKeySSID"); Assert.NotNull(dict [CaptiveNetwork.NetworkInfoKeySSIDData], "NetworkInfoKeySSIDData"); } else { Assert.Fail("Unexpected dictionary result with {0} items", dict.Count); } }
Task <WifiNetwork> IWifiService.GetCurrentlyConnectedWifiNetwork() { WifiNetwork wifiNetwork = null; CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out var info); foreach (var pair in info) { if (pair.Key.ToString() == "SSID") { wifiNetwork = new WifiNetwork { SSID = pair.Value.ToString(), }; } } return(Task.FromResult(wifiNetwork)); }
public override void ViewDidLoad() { base.ViewDidLoad(); String[] interfaces; CaptiveNetwork.TryGetSupportedInterfaces(out interfaces); if (interfaces != null && interfaces.Length >= 1) { NSDictionary dict; CaptiveNetwork.TryCopyCurrentNetworkInfo(interfaces[0], out dict); if (dict != null) { var bssid = (NSString)dict[CaptiveNetwork.NetworkInfoKeyBSSID]; var ssid = (NSString)dict[CaptiveNetwork.NetworkInfoKeySSID]; } } StartConnecting(); }
protected override void Refresh() { var profiles = Connectivity.ConnectionProfiles; if (profiles.Contains(ConnectionProfile.Cellular)) { Status = NetStatus.Wwan; } else if (profiles.Contains(ConnectionProfile.WiFi)) { try { CheckStatus(CaptiveNetwork.TryGetSupportedInterfaces(out string[] interfaces)); foreach (string name in interfaces) { CheckStatus(CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out NSDictionary dict)); using (dict) { if (dict.TryGetValue(CaptiveNetwork.NetworkInfoKeySSID, out NSObject ssid)) { Status = NetStatus.Wlan; Ssid = ssid.ToString(); } } } } catch (Exception) { Status = NetStatus.Unknown; } } else if (profiles.Contains(ConnectionProfile.Ethernet)) { Status = NetStatus.Lan; } else { Status = NetStatus.Unknown; } }
public async Task <WifiNetwork> GetCurrentlyConnectedWifiNetwork() { WifiNetwork wifiNetwork = null; CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out var info); if (info != null) { foreach (var pair in info) { if (pair.Key.ToString() == "SSID") { wifiNetwork = new WifiNetwork { SSID = pair.Value.ToString(), }; } } } return(await Task.FromResult(wifiNetwork)); }
public string GetConnectedAp() { //foreach (var network in NEHotspotHelper.SupportedNetworkInterfaces) //{ // if (!string.IsNullOrEmpty(network.Ssid)) // return network.Ssid; //} //return string.Empty; //check for iOS 11+ NSDictionary dict; var status = CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out dict); if (status == StatusCode.NoKey) { return(string.Empty); } var bssid = dict[CaptiveNetwork.NetworkInfoKeyBSSID]; var ssid = dict[CaptiveNetwork.NetworkInfoKeySSID]; var ssiddata = dict[CaptiveNetwork.NetworkInfoKeySSIDData]; return(ssid.ToString()); }
public void SetSupportedSSIDs() { TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 10, 8, throwIfOtherPlatform: false); #if MONOMAC || __MACCATALYST__ bool supported = true; #else // that API is deprecated in iOS9 - and it might be why it returns false (or not) bool supported = !TestRuntime.CheckXcodeVersion(7, 0); #endif #if __TVOS__ #if !NET Assert.Throws <NotSupportedException> (() => CaptiveNetwork.SetSupportedSSIDs(new string [2] { "one", "two" }), "set"); #endif #else Assert.That(CaptiveNetwork.SetSupportedSSIDs(new string [2] { "one", "two" }), Is.EqualTo(supported), "set"); #endif }
public void TryCopyCurrentNetworkInfo() { NSDictionary dict; StatusCode status; #if __TVOS__ Assert.Throws <NotSupportedException> (() => { status = CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out dict); }); #else status = CaptiveNetwork.TryCopyCurrentNetworkInfo("en0", out dict); // No network, ignore test if (status == StatusCode.NoKey) { return; } Assert.AreEqual(StatusCode.OK, status, "Status"); // To get a non-null dictionary back, we must (https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo) // * Use core location, and request (and get) authorization to use location information // * Add the 'com.apple.developer.networking.wifi-info' entitlement // I tried this, and still got null back, so just assert that we get null. Assert.IsNull(dict, "Dictionary"); #endif }
public void TryCopyCurrentNetworkInfo_Null() { NSDictionary dict; CaptiveNetwork.TryCopyCurrentNetworkInfo(null, out dict); }
public void SetSupportedSSIDs_Null() { CaptiveNetwork.SetSupportedSSIDs(null); }