Example #1
0
        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;
                    }
                }
            }
        }
Example #2
0
        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");
        }
Example #3
0
        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();
                    });
                }
            });
        }
Example #4
0
        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();
        }
Example #5
0
        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>();

                string[] supportedInterfaces;
                var status = CaptiveNetwork.TryGetSupportedInterfaces(out supportedInterfaces);

                if (status == StatusCode.OK && supportedInterfaces != null)
                {
                    foreach (var @interface in supportedInterfaces)
                    {
                        NSDictionary dict;
                        CaptiveNetwork.TryCopyCurrentNetworkInfo(@interface, out 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);
        }