public static async Task <Response <GoogleGeolocationResult> > GetLocationAsync(string key) { try { var networks = NativeWifi.EnumerateBssNetworks(); var wifiAccessPoints = networks.Select(i => new Wifiaccesspoint() { channel = i.Channel, macAddress = i.Bssid.ToString(), signalStrength = i.SignalStrength, }).ToArray(); // //System.IO.File.WriteAllText("vezarat.txt", Newtonsoft.Json.JsonConvert.SerializeObject(wifiAccessPoints)); foreach (var item in wifiAccessPoints) { Debug.WriteLine($"mac: {item.macAddress}, signal:{item.signalStrength}, channel: {item.channel}"); } return(await GetLocationAsync(key, wifiAccessPoints)); //var url = $"https://www.googleapis.com/geolocation/v1/geolocate?key={key}"; //return await Helpers.NetHelper.HttpPostAsync<GoogleGeolocationResult>(url, parameter); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); //return new GoogleGeolocationResult() { accuracy = int.MaxValue }; return(ResponseFactory.CreateError <GoogleGeolocationResult>(ex.GetMessagePlus())); } }
public static async Task <ApiResults.GoogleMapsGeolocationJsonResult> GetLocation(string key) { try { var networks = NativeWifi.EnumerateBssNetworks(); var parameter = new GoogleMapsGeolocationParameters() { wifiAccessPoints = networks.Select(i => new Wifiaccesspoint() { channel = i.Channel, macAddress = i.Bssid.ToString(), signalStrength = i.SignalStrength, }).ToArray() }; var url = $"https://www.googleapis.com/geolocation/v1/geolocate?key={key}"; return(await Helpers.NetHelper.HttpPost <ApiResults.GoogleMapsGeolocationJsonResult>(url, parameter)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return(new ApiResults.GoogleMapsGeolocationJsonResult() { accuracy = int.MaxValue }); } }
private static void ShowInformation() { Trace.WriteLine("===== Usable Interfaces ====="); foreach (var interfaceInfo in NativeWifi.EnumerateInterfaces()) { Trace.WriteLine($"Interface: {interfaceInfo.Description} ({interfaceInfo.Id})"); } Trace.WriteLine("===== Usable Interface Connections ====="); foreach (var interfaceInfo in NativeWifi.EnumerateInterfaceConnections()) { Trace.WriteLine($"{{Interface: {interfaceInfo.Description} ({interfaceInfo.Id})"); Trace.WriteLine($" Connection: {interfaceInfo.ConnectionMode}"); Trace.WriteLine($" RadioOn: {interfaceInfo.IsRadioOn}"); Trace.WriteLine($" Connected: {interfaceInfo.IsConnected}"); Trace.WriteLine($" Profile: {interfaceInfo.ProfileName}}}"); } Trace.WriteLine("===== Available Network SSIDs ====="); foreach (var ssid in NativeWifi.EnumerateAvailableNetworkSsids()) { Trace.WriteLine($"SSID: {ssid}"); } Trace.WriteLine("===== Connected Network SSIDs ====="); foreach (var ssid in NativeWifi.EnumerateConnectedNetworkSsids()) { Trace.WriteLine($"SSID: {ssid}"); } Trace.WriteLine("===== Available Networks ====="); foreach (var network in NativeWifi.EnumerateAvailableNetworks()) { Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})"); Trace.WriteLine($" SSID: {network.Ssid}"); Trace.WriteLine($" BSS: {network.BssType}"); Trace.WriteLine($" SignalQuality: {network.SignalQuality}"); Trace.WriteLine($" Security: {network.IsSecurityEnabled}}}"); } Trace.WriteLine("===== Available Network Groups ====="); foreach (var network in NativeWifi.EnumerateAvailableNetworkGroups()) { Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})"); Trace.WriteLine($" SSID: {network.Ssid}"); Trace.WriteLine($" BssNetworks: {network.BssNetworks.Count}"); Trace.WriteLine($" SignalQuality: {network.SignalQuality}"); Trace.WriteLine($" LinkQuality: {network.LinkQuality}"); Trace.WriteLine($" Band: {network.Band} GHz"); Trace.WriteLine($" Channel: {network.Channel}}}"); } Trace.WriteLine("===== BSS Networks ====="); foreach (var network in NativeWifi.EnumerateBssNetworks()) { Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})"); Trace.WriteLine($" SSID: {network.Ssid}"); Trace.WriteLine($" BSS: {network.BssType}"); Trace.WriteLine($" BSSID: {network.Bssid}"); Trace.WriteLine($" SignalStrength: {network.SignalStrength}"); Trace.WriteLine($" LinkQuality: {network.LinkQuality}"); Trace.WriteLine($" Frequency: {network.Frequency} KHz"); Trace.WriteLine($" Band: {network.Band} GHz"); Trace.WriteLine($" Channel: {network.Channel}}}"); } Trace.WriteLine("===== Network Profile Names ====="); foreach (var name in NativeWifi.EnumerateProfileNames()) { Trace.WriteLine($"Name: {name}"); } Trace.WriteLine("===== Network Profiles ====="); foreach (var profile in NativeWifi.EnumerateProfiles()) { Trace.WriteLine($"{{Name: {profile.Name}"); Trace.WriteLine($" Interface: {profile.Interface.Description} ({profile.Interface.Id})"); Trace.WriteLine($" SSID: {profile.Document.Ssid}"); Trace.WriteLine($" BSS: {profile.Document.BssType}"); Trace.WriteLine($" Authentication: {profile.Document.Authentication}"); Trace.WriteLine($" Encryption: {profile.Document.Encryption}"); Trace.WriteLine($" AutoConnect: {profile.Document.IsAutoConnectEnabled}"); Trace.WriteLine($" AutoSwitch: {profile.Document.IsAutoSwitchEnabled}"); Trace.WriteLine($" Position: {profile.Position}}}"); } Trace.WriteLine("===== Network Profile Radios ====="); foreach (var profile in NativeWifi.EnumerateProfileRadios()) { Trace.WriteLine($"{{Name: {profile.Name}"); Trace.WriteLine($" Interface: {profile.Interface.Description} ({profile.Interface.Id})"); Trace.WriteLine($" SSID: {profile.Document.Ssid}"); Trace.WriteLine($" RadioOn: {profile.IsRadioOn}"); Trace.WriteLine($" Connected: {profile.IsConnected}"); Trace.WriteLine($" SignalQuality: {profile.SignalQuality}"); Trace.WriteLine($" LinkQuality: {profile.LinkQuality}"); Trace.WriteLine($" Band: {profile.Band} GHz"); Trace.WriteLine($" Channel: {profile.Channel}}}"); } }
/// <summary> /// Enumerates wireless LAN channels whose signal strength go beyond a specified threshold. /// </summary> /// <param name="signalStrengthThreshold">Threshold of signal strength</param> /// <returns>Channel numbers</returns> public static IEnumerable <int> EnumerateNetworkChannels(int signalStrengthThreshold) { return(NativeWifi.EnumerateBssNetworks() .Where(x => x.SignalStrength > signalStrengthThreshold) .Select(x => x.Channel)); }
//4.1秒ごとにWifi測る(現在位置部屋特定) //このタイマーは授業中のみ実施 private async void timer2_Tick(object sender, EventArgs e) { WifiInfo wifiInfo = new WifiInfo(); foreach (BssNetworkPack network in NativeWifi.EnumerateBssNetworks()) { wifiInfo.setSSID(network.Ssid.ToString()); wifiInfo.setBSSID(network.Bssid.ToString().ToLower()); wifiInfo.setRSSI(network.SignalStrength); } string rssi = WifiRSSI.SVMList(wifiInfo); Console.WriteLine(rssi); //ここからサーバー通信 WebClient wc = new WebClient(); NameValueCollection ps = new NameValueCollection(); ps.Add("rssi", rssi); byte[] resData = wc.UploadValues(url, ps); wc.Dispose(); string resText = System.Text.Encoding.UTF8.GetString(resData); Console.WriteLine(resText); resText = resText.Trim(); resText = WifiRSSI.RoomConv(resText); //label2.Text = resText; isRoom = resText; int num = 0; for (int i = 0; i < UserData.scheduleClasses.Count; i++) { ScheduleClass schedule = UserData.scheduleClasses[i]; for (int j = 0; j < schedule.TimeSize(); j++) { TimeClass time = schedule.getTime(j); DateTime beginTime = time.getBeginTime(); DateTime endTime = time.getEndTime(); TimeSpan beginSpan = beginTime.TimeOfDay; TimeSpan endSpan = endTime.TimeOfDay; TimeSpan fromSpan = DateTime.Now.TimeOfDay - beginSpan; TimeSpan toSpan = DateTime.Now.TimeOfDay - endSpan; double beginSecond = fromSpan.TotalSeconds; double endSecond = toSpan.TotalSeconds; bool[] day = time.getDay(); //実行中である if (beginSecond > 0 && endSecond < 0 && day[(int)DateTime.Now.DayOfWeek]) { num++; label1.Text = "現在"; label3.Text = UserData.scheduleClasses[i].getName(); //部屋にいるか? if (isRoom == time.getRoomName()) { label4.Visible = true; //講義資料自動オープンをするよ for (int k = 0; k < UserData.scheduleClasses[i].DocumentSize(); k++) { DocumentClass document = UserData.scheduleClasses[i].getDocument(k); if (document.getOpen() && !time.getClass()) { //"C:\test\1.txt"を関連付けられたアプリケーションで開く System.Diagnostics.Process p = System.Diagnostics.Process.Start(Environment.CurrentDirectory + "\\" + UserData.scheduleClasses[i].getName() + "\\" + document.getDocumentName()); if (k == UserData.scheduleClasses[i].DocumentSize() - 1) { time.setClass(true); UserData.scheduleClasses[i].renewTime(time, j); } //この辺に出席を送信する処理入れたい Console.WriteLine(document.getDocumentName() + " 開いた"); } await Task.Delay(1000); } } } } } //実行中のものがないときタイマー2を切ってタイマー1をオンにする if (num == 0) { timer1.Enabled = true; label3.Visible = false; label4.Visible = false; timer2.Enabled = false; } //更新 RefreshAsync(); }
private static void ShowInformation() { Trace.WriteLine("[Usable Interfaces]"); foreach (var interfaceInfo in NativeWifi.EnumerateInterfaces()) { Trace.WriteLine($"Interface: {interfaceInfo.Description} ({interfaceInfo.Id})"); } Trace.WriteLine("[Available Network SSIDs]"); foreach (var ssid in NativeWifi.EnumerateAvailableNetworkSsids()) { Trace.WriteLine($"SSID: {ssid}"); } Trace.WriteLine("[Connected Network SSIDs]"); foreach (var ssid in NativeWifi.EnumerateConnectedNetworkSsids()) { Trace.WriteLine($"SSID: {ssid}"); } Trace.WriteLine("[Available Networks]"); foreach (var network in NativeWifi.EnumerateAvailableNetworks()) { Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})"); Trace.WriteLine($" SSID: {network.Ssid}"); Trace.WriteLine($" BSS: {network.BssType}"); Trace.WriteLine($" Signal: {network.SignalQuality}"); Trace.WriteLine($" Security: {network.IsSecurityEnabled}}}"); } Trace.WriteLine("[BSS Networks]"); foreach (var network in NativeWifi.EnumerateBssNetworks()) { Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})"); Trace.WriteLine($" SSID: {network.Ssid}"); Trace.WriteLine($" BSS: {network.BssType}"); Trace.WriteLine($" BSSID: {network.Bssid}"); Trace.WriteLine($" Signal: {network.SignalStrength}"); Trace.WriteLine($" Link: {network.LinkQuality}"); Trace.WriteLine($" Frequency: {network.Frequency}"); Trace.WriteLine($" Channel: {network.Channel}}}"); } Trace.WriteLine("[Network Profile Names]"); foreach (var name in NativeWifi.EnumerateProfileNames()) { Trace.WriteLine($"Name: {name}"); } Trace.WriteLine("[Network Profiles]"); foreach (var profile in NativeWifi.EnumerateProfiles()) { Trace.WriteLine($"{{Name: {profile.Name}"); Trace.WriteLine($" Interface: {profile.Interface.Description} ({profile.Interface.Id})"); Trace.WriteLine($" SSID: {profile.Ssid}"); Trace.WriteLine($" BSS: {profile.BssType}"); Trace.WriteLine($" Authentication: {profile.Authentication}"); Trace.WriteLine($" Encryption: {profile.Encryption}"); Trace.WriteLine($" Signal: {profile.SignalQuality}"); Trace.WriteLine($" Position: {profile.Position}"); Trace.WriteLine($" Automatic: {profile.IsAutomatic}"); Trace.WriteLine($" Connected: {profile.IsConnected}}}"); } }
private static void ShowInformation() { Trace.WriteLine("[Usable Interfaces]"); foreach (var interfaceInfo in NativeWifi.EnumerateInterfaces()) { Trace.WriteLine($"Interface: {interfaceInfo.Description} ({interfaceInfo.Id})"); } Trace.WriteLine(""); Trace.WriteLine("[Available Network SSIDs]"); foreach (var ssid in NativeWifi.EnumerateAvailableNetworkSsids()) { Trace.WriteLine($"SSID: {ssid}"); } Trace.WriteLine(""); Trace.WriteLine("[Connected Network SSIDs]"); foreach (var ssid in NativeWifi.EnumerateConnectedNetworkSsids()) { Trace.WriteLine($"SSID: {ssid}"); } Trace.WriteLine(""); Trace.WriteLine("[Available Networks]"); foreach (var network in NativeWifi.EnumerateAvailableNetworks()) { Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})"); Trace.WriteLine($" SSID: {network.Ssid}"); Trace.WriteLine($" BSS: {network.BssType}"); Trace.WriteLine($" Signal: {network.SignalQuality}"); Trace.WriteLine($" Security: {network.IsSecurityEnabled}"); Trace.WriteLine($" Auth Algorithm: {network.AuthAlgorithm.ToString()}"); Trace.WriteLine($" Has Profile: {network.IsHasProfile} {(network.IsHasProfile ? "(" + network.ProfileName + ")" : network.ProfileName)}"); Trace.WriteLine($" Cipher Algorithm: {network.CipherAlgorithm.ToString()}}}"); var bssNetworks = NativeWifi.EnumerateBssNetworks(network); if (bssNetworks != null) { Trace.WriteLine("[Child BSS Networks]"); foreach (var bssNetwork in bssNetworks) { Trace.WriteLine($"{{BSSID: {bssNetwork.Bssid}"); Trace.WriteLine($" SSID: {bssNetwork.Ssid}"); Trace.WriteLine($" BSS: {bssNetwork.BssType}"); Trace.WriteLine($" Signal: {bssNetwork.SignalStrength}"); Trace.WriteLine($" Link: {bssNetwork.LinkQuality}"); Trace.WriteLine($" Frequency: {bssNetwork.Frequency}"); Trace.WriteLine($" Channel: {bssNetwork.Channel}}}"); } } } Trace.WriteLine(""); Trace.WriteLine("[BSS Networks]"); foreach (var network in NativeWifi.EnumerateBssNetworks()) { Trace.WriteLine($"{{Interface: {network.Interface.Description} ({network.Interface.Id})"); Trace.WriteLine($" SSID: {network.Ssid}"); Trace.WriteLine($" BSS: {network.BssType}"); Trace.WriteLine($" BSSID: {network.Bssid}"); Trace.WriteLine($" Signal: {network.SignalStrength}"); Trace.WriteLine($" Link: {network.LinkQuality}"); Trace.WriteLine($" Frequency: {network.Frequency}"); Trace.WriteLine($" Channel: {network.Channel}}}"); } Trace.WriteLine(""); Trace.WriteLine("[Network Profile Names]"); foreach (var name in NativeWifi.EnumerateProfileNames()) { Trace.WriteLine($"Name: {name}"); } Trace.WriteLine(""); Trace.WriteLine("[Network Profiles]"); foreach (var profile in NativeWifi.EnumerateProfiles()) { Trace.WriteLine($"{{Name: {profile.Name}"); Trace.WriteLine($" Interface: {profile.Interface.Description} ({profile.Interface.Id})"); Trace.WriteLine($" SSID: {profile.Document.Ssid}"); Trace.WriteLine($" BSS: {profile.Document.BssType}"); Trace.WriteLine($" Authentication: {profile.Document.Authentication}"); Trace.WriteLine($" Encryption: {profile.Document.Encryption}"); Trace.WriteLine($" AutoConnect: {profile.Document.IsAutoConnectEnabled}"); Trace.WriteLine($" AutoSwitch: {profile.Document.IsAutoSwitchEnabled}"); Trace.WriteLine($" Position: {profile.Position}"); Trace.WriteLine($" RadioOn: {profile.IsRadioOn}"); Trace.WriteLine($" Signal: {profile.SignalQuality}"); Trace.WriteLine($" Connected: {profile.IsConnected}}}"); } }