Esempio n. 1
0
        private void LoadIpPools()
        {
            PoolDic.Add("@Inner", IpPool.CreateFromText(Resources.InnerIpSet));
            try
            {
                var fns = Directory.GetFiles(Path.GetDirectoryName(Application.ExecutablePath), "*.ip.txt");
                foreach (var fn in fns)
                {
                    using (var sr = File.OpenText(fn))
                    {
                        var pool = IpPool.CreateFromText(sr.ReadToEnd());
                        if (pool.Count > 0)
                        {
                            PoolDic.Add(Path.GetFileNameWithoutExtension(fn), pool);
                        }
                    }
                }
            }
            catch { }

            SetPools();
            cbPools.SelectedIndex = 0;

            new Thread(LoadSpfPools).Start();
        }
Esempio n. 2
0
        private void LoadSpfPools()
        {
            try
            {
                var domains = new[] { "google.com" };
                if (File.Exists("spf.txt"))
                {
                    using (var sr = File.OpenText("spf.txt"))
                        domains = (from Match m in RxDomain.Matches(sr.ReadToEnd()) select m.Value).ToArray();
                }
                PoolDic.Add("@Spf.Ipv4", IpPool.CreateFromDomains(domains));

                SetPools();
            }
            catch (Exception) { }
        }
Esempio n. 3
0
        private void bAddIpRange_Click(object sender, EventArgs e)
        {
            if (IsTesting())
            {
                return;
            }

            var str = tbIpRange.Text;

            tbIpRange.ResetText();
            if (str == "")
            {
                return;
            }

            var pool = IpPool.CreateFromText(str);

            if (pool.Count == 0)
            {
                return;
            }

            ImportIps(pool);
        }
Esempio n. 4
0
        public static IpPool CreateFromText(string text)
        {
            var pool = new IpPool();

            try
            {
                var ms = RxIpv4.Matches(text);
                foreach (Match m in ms)
                {
                    var  astr = m.Groups["astr"].Value;
                    var  mstr = m.Groups["mstr"].Value;
                    var  range = m.Groups["range"].Value;
                    var  domain = m.Groups["domain"].Value;
                    uint min = 0, max = 0;
                    if (mstr != string.Empty)
                    {
                        var ip  = IPAddress.Parse(astr);
                        var mov = 32 - Convert.ToInt32(mstr);
                        var msk = (0xffffffff >> mov) << mov;
                        var bs  = ip.GetAddressBytes();
                        Array.Reverse(bs);
                        var num = BitConverter.ToUInt32(bs, 0);
                        min = num & msk;
                        max = num | (0xffffffff ^ msk);

                        pool.ImportRange(min, max);
                    }
                    else if (range != string.Empty)
                    {
                        var sps = range.Split('.');
                        for (var i = 0; i < 4; i++)
                        {
                            if (sps[i].Contains("-"))
                            {
                                var tps = sps[i].Split('-');

                                var va = uint.Parse(tps[0]);
                                var vb = uint.Parse(tps[1]);

                                min = (min << 8) | (va & 0xff);
                                max = (max << 8) | (vb & 0xff);
                            }
                            else
                            {
                                var v = uint.Parse(sps[i]);
                                min = (min << 8) | (v & 0xff);
                                max = (max << 8) | (v & 0xff);
                            }
                        }

                        pool.ImportRange(min, max);
                    }
                    else if (domain != string.Empty)
                    {
                        foreach (var ip in from addr in Dns.GetHostAddresses(domain) where addr.AddressFamily == AddressFamily.InterNetwork let dat = addr.GetAddressBytes() where dat[3] != 0 && dat[3] != 255 select new Ip(dat))
                        {
                            pool.Add(ip);
                        }
                    }
                }
            }
            catch { }
            pool.TrimExcess();
            return(pool);
        }