protected override void UseDefaultDns() { foreach (var i in Enumerable.Range(136, 10)) { IpList.Add(IPAddress.Parse($"210.140.92.{i}")); } }
/// <summary> /// Splits the incoming ip string of the format "IP,IP" example "10.2.0.0,10.3.0.0" and adds the result to the IPList /// </summary> /// <param name="ips">The ips.</param> /// <param name="list">The list.</param> private void SplitAndAddSingleIPs(string ips, IpList list) { var splitSingleIPs = ips.Split(','); foreach (string ip in splitSingleIPs) { list.Add(ip); } }
private static void AddRestrictionToIpList(IpList list, string restriction) { if (string.IsNullOrEmpty(restriction)) { return; } if (StringUtils.Contains(restriction, "-")) { restriction = restriction.Trim(' ', '-'); var arr = restriction.Split('-'); list.AddRange(arr[0].Trim(), arr[1].Trim()); } else if (StringUtils.Contains(restriction, "*")) { var ipPrefix = restriction.Substring(0, restriction.IndexOf('*')); ipPrefix = ipPrefix.Trim(' ', '.'); var dotNum = StringUtils.GetCount(".", ipPrefix); string ipNumber; string mask; if (dotNum == 0) { ipNumber = ipPrefix + ".0.0.0"; mask = "255.0.0.0"; } else if (dotNum == 1) { ipNumber = ipPrefix + ".0.0"; mask = "255.255.0.0"; } else { ipNumber = ipPrefix + ".0"; mask = "255.255.255.0"; } list.Add(ipNumber, mask); } else { list.Add(restriction); } }
/// <summary> /// Splits the incoming ip string of the format "IP;MASK,IP;MASK" example "10.2.0.0;255.255.0.0,10.3.0.0;255.255.0.0" and adds the result to the IPList /// </summary> /// <param name="ips">The ips.</param> /// <param name="list">The list.</param> private void SplitAndAddMaskedIPs(string ips, IpList list) { var splitMaskedIPs = ips.Split(','); foreach (string maskedIp in splitMaskedIPs) { var ipAndMask = maskedIp.Split(';'); list.Add(ipAndMask[0], ipAndMask[1]); // IP;MASK } }
protected override void UseDefaultDns() { IpList.Add(IPAddress.Parse("210.140.131.219")); IpList.Add(IPAddress.Parse("210.140.131.223")); IpList.Add(IPAddress.Parse("210.140.131.226")); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); #region FindView var listView = FindViewById <ListView>(Resource.Id.listView1); var startBtn = FindViewById <Button>(Resource.Id.MyButton); var airplaneBtn = FindViewById <Button>(Resource.Id.MyButton1); var message = FindViewById <TextView>(Resource.Id.message); var systemStateTextView = FindViewById <TextView>(Resource.Id.textView2); var ssid = FindViewById <EditText>(Resource.Id.ssidEdit); var pwd = FindViewById <EditText>(Resource.Id.pwdEdit); var check = FindViewById <CheckBox>(Resource.Id.checkBox1); var timerText = FindViewById <EditText>(Resource.Id.timeEdit); listView.SetBackgroundColor(Color.Black); #endregion startBtn.Click += (s, e) => { var btn = (Button)s; if (btn.Text == "结束工作") { S.EndTask(() => { Count = 0; message.Text = $"设置WiFi热点和密码,否则以当前热点状态创建热点-{Count}"; }); btn.Text = "开始工作"; } else { var wifiState = WifiToolUtils.GetWifiState(BaseContext); if (wifiState == WifiState.Enabled) { WifiToolUtils.SetWifiEnabled(BaseContext, false); } var wifiApModel = pwd.Text.Length >= 8 && !string.IsNullOrWhiteSpace(ssid.Text) && !string.IsNullOrWhiteSpace(pwd.Text) ? new WifiapViewModel(ssid.Text.Trim(), pwd.Text.Trim()) : null; if (WifiToolUtils.GetWifiApState(BaseContext) != WifiApState.Enabled || WifiToolUtils.GetWifiApState(BaseContext) != WifiApState.Enabling) { WifiToolUtils.SetWifiApEnabled(BaseContext, true, wifiApModel); } S.StartTask(state => { Task.Run(() => { RunOnUiThread(() => { wifiState = WifiToolUtils.GetWifiState(BaseContext); var wifiApState = WifiToolUtils.GetWifiApState(BaseContext); var airplaneModeState = AirplaneModeUtils.IsAirplaneModeOn(BaseContext); Count++; message.Text = $"设置WiFi热点和密码,否则以当前热点状态创建热点-{Count}"; systemStateTextView.Text = $"wifi状态:{wifiState}热点状态:{wifiApState}-------飞行模式:{airplaneModeState}"; var dataSource = WifiToolUtils.GetConnectedHotIp(); foreach (var item in dataSource) { var ip = IpList.FirstOrDefault(c => c == item.Ip); if (ip == null && item.IsTrue) { IpList.Add(item.Ip); } else { Reset(); } if (check.Checked) { int timer; var x = timerText.Text; if (string.IsNullOrWhiteSpace(x)) { timer = 60; } else { timer = int.Parse(x); } if (timer <= Count) { Reset(); } } } var listDataSource = dataSource.Select(item => $"地址:{item.Ip}---连接状态:{item.IsTrue}").ToArray(); listView.Adapter = new ArrayAdapter <string>(BaseContext, Android.Resource.Layout.SimpleListItem1, listDataSource); }); }); }); btn.Text = "结束工作"; } }; airplaneBtn.Click += delegate { AirplaneModeUtils.SetAirplane(BaseContext, !AirplaneModeUtils.IsAirplaneModeOn(BaseContext)); }; }