コード例 #1
0
 protected override void UseDefaultDns()
 {
     foreach (var i in Enumerable.Range(136, 10))
     {
         IpList.Add(IPAddress.Parse($"210.140.92.{i}"));
     }
 }
コード例 #2
0
        public static bool IsAllowed(string ipAddress, List <string> blockList, List <string> allowList)
        {
            var isAllowed = true;

            if (blockList != null && blockList.Count > 0)
            {
                var list = new IpList();
                foreach (var restriction in blockList)
                {
                    AddRestrictionToIpList(list, restriction);
                }
                if (list.CheckNumber(ipAddress))
                {
                    isAllowed = false;
                }
            }
            else if (allowList != null && allowList.Count > 0)
            {
                isAllowed = false;
                var list = new IpList();
                foreach (var restriction in allowList)
                {
                    AddRestrictionToIpList(list, restriction);
                }
                if (list.CheckNumber(ipAddress))
                {
                    isAllowed = true;
                }
            }

            return(isAllowed);
        }
コード例 #3
0
 private void btnUnmarkAll_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < IpList.Items.Count; i++)
     {
         IpList.SetItemChecked(i, false);
     }
 }
コード例 #4
0
    /// <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);
        }
    }
コード例 #5
0
 private void btnDeleteSelected_Click(object sender, EventArgs e)
 {
     for (int i = IpList.Items.Count - 1; i >= 0; i--)
     {
         if (IpList.GetItemChecked(i))
         {
             IpList.Items.RemoveAt(i);
         }
     }
 }
コード例 #6
0
    /// <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
        }
    }
コード例 #7
0
 private void ButtonsOpacityTo0_Completed(object sender, EventArgs e)
 {
     if (State == MyStates.ResultsDisplaying)
     {
         ScanResults.BeginAnimation(Border.HeightProperty, CloseButtonBarMove);
     }
     else if (State == MyStates.IpListDisplaying)
     {
         IpList.BeginAnimation(Border.HeightProperty, CloseIpListButtonBarMove);
     }
 }
コード例 #8
0
 /// <summary>
 /// ComboBox_KeyDown
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ComboBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
 {
     if (e.Key == System.Windows.Input.Key.Return)
     {
         string newItemValue = ((System.Windows.Controls.TextBox)e.OriginalSource).Text;
         var    item         = IpList.SingleOrDefault(x => x == newItemValue);
         if (item == null)
         {
             IpList.Insert(0, newItemValue);
         }
     }
 }
コード例 #9
0
ファイル: PageUtils.cs プロジェクト: ooyuan1984/cms-1
        public static bool IsVisitAllowed(ISettingsManager settingsManager, HttpRequest request)
        {
            var isAllowed = true;

            if (!string.IsNullOrEmpty(settingsManager.AdminRestrictionHost))
            {
                var currentHost = RemoveProtocolFromUrl(GetHost(request));
                if (!StringUtils.StartsWithIgnoreCase(currentHost, RemoveProtocolFromUrl(settingsManager.AdminRestrictionHost)))
                {
                    isAllowed = false;
                }
            }

            if (isAllowed)
            {
                var userIp = GetIpAddress(request);

                if (settingsManager.AdminRestrictionBlockList != null && settingsManager.AdminRestrictionBlockList.Length > 0)
                {
                    var list = new IpList();
                    foreach (var restriction in settingsManager.AdminRestrictionBlockList)
                    {
                        AddRestrictionToIpList(list, restriction);
                    }
                    if (list.CheckNumber(userIp))
                    {
                        isAllowed = false;
                    }
                }
                else if (settingsManager.AdminRestrictionAllowList != null && settingsManager.AdminRestrictionAllowList.Length > 0)
                {
                    isAllowed = false;
                    var list = new IpList();
                    foreach (var restriction in settingsManager.AdminRestrictionAllowList)
                    {
                        AddRestrictionToIpList(list, restriction);
                    }
                    if (list.CheckNumber(userIp))
                    {
                        isAllowed = true;
                    }
                }
            }

            return(isAllowed);
        }
コード例 #10
0
        private void BtnFormList_Click(object sender, EventArgs e)
        {
            List <string> ips = new List <string>();

            for (int i = 0; i < IpList.Items.Count; i++)
            {
                if (IpList.GetItemChecked(i))
                {
                    ips.Add(IpList.Items[i].ToString());
                }
            }
            MainForm main = this.Owner as MainForm;

            if (main != null)
            {
                main.clients = ips;
            }
            this.Close();
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
        public IPadresses()
        {
            InitializeComponent();
            IpList.CheckOnClick = true;
            List <string> ips = new List <string>();

            for (int i = 0; i < IpList.Items.Count; i++)
            {
                if (IpList.GetItemChecked(i))
                {
                    ips.Add(IpList.Items[i].ToString());
                }
            }
            MainForm main = this.Owner as MainForm;

            if (main != null)
            {
                main.clients = ips;
            }
        }
コード例 #13
0
        private void BeginBackSwapAnimation()
        {
            ScanResults.Visibility = Visibility.Visible;
            TranslateTransform t = new TranslateTransform();

            ScanResults.RenderTransform = t;

            TranslateTransform t2 = new TranslateTransform();

            IpList.RenderTransform = t2;

            IpList.BeginAnimation(Border.OpacityProperty, SwapOpacityTo0);
            ScanResults.BeginAnimation(Border.OpacityProperty, SwapOpacityTo1);

            t.BeginAnimation(TranslateTransform.XProperty, SwapResultXMove);
            t.BeginAnimation(TranslateTransform.YProperty, SwapResultYMove);

            t2.BeginAnimation(TranslateTransform.XProperty, SwapIpListXMove);
            t2.BeginAnimation(TranslateTransform.YProperty, SwapIpListYMove);
        }
コード例 #14
0
        static void GetServerList()
        {
            Assembly asm = Assembly.GetExecutingAssembly();

            IPList = new IpList();
            string configFile = Path.Combine(Directory.GetParent(asm.Location).FullName, "OCXLogin.xml");

            if (System.IO.File.Exists(configFile))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(configFile);
                foreach (XmlNode item in doc.SelectNodes("//Login"))
                {
                    string ip   = item.SelectSingleNode("IP").InnerText;
                    uint   port = Convert.ToUInt32(item.SelectSingleNode("Port").InnerText);
                    string user = item.SelectSingleNode("User").InnerText;
                    string pass = item.SelectSingleNode("Pass").InnerText;
                    IPList.AddIp(new ConnectionParam()
                    {
                        IPAddress = ip, Port = (int)port, DeviceNo = user
                    });
                }
            }
        }
コード例 #15
0
 private void OpenIpListButtonBar()
 {
     IpList.BeginAnimation(Border.HeightProperty, OpenIpListButtonBarMove);
 }
コード例 #16
0
ファイル: MainActivity.cs プロジェクト: SkillUsing/Xamarin
        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));
            };
        }
コード例 #17
0
        public static bool IsVisitAllowed(Config config)
        {
            var restrictionType = ERestrictionTypeUtils.GetEnumType(config.IpRestrictionType);

            var restrictionList = new List <string>();

            if (restrictionType == ERestrictionType.BlackList)
            {
                restrictionList = new List <string>(config.IpBlackList.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries));
            }
            else if (restrictionType == ERestrictionType.WhiteList)
            {
                restrictionList = new List <string>(config.IpWhiteList.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries));
            }

            var isAllowed = true;

            if (restrictionType != ERestrictionType.None)
            {
                var userIp = GetIpAddress();
                if (restrictionType == ERestrictionType.BlackList)
                {
                    var list = new IpList();
                    foreach (var restriction in restrictionList)
                    {
                        AddRestrictionToIpList(list, restriction);
                    }
                    if (list.CheckNumber(userIp))
                    {
                        isAllowed = false;
                    }
                }
                else if (restrictionType == ERestrictionType.WhiteList)
                {
                    if (restrictionList.Count > 0)
                    {
                        isAllowed = false;
                        var list = new IpList();
                        foreach (var restriction in restrictionList)
                        {
                            AddRestrictionToIpList(list, restriction);
                        }
                        if (list.CheckNumber(userIp))
                        {
                            isAllowed = true;
                        }
                    }
                }
            }
            if (isAllowed)
            {
                if (config.IsHostRestriction && !string.IsNullOrEmpty(config.Host))
                {
                    var currentHost = RemoveProtocolFromUrl(GetHost());
                    if (!StartsWithIgnoreCase(currentHost, RemoveProtocolFromUrl(config.Host)))
                    {
                        isAllowed = false;
                    }
                }
            }
            return(isAllowed);
        }
コード例 #18
0
 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"));
 }