Exemple #1
0
        public String getIPForStore(int StoreID, Boolean Relocation)
        {
            if (!IsIPv6())
            {
                String fourDigitStoreNumber = StoreID.ToString("D" + 4);
                String strIpFormat          = "";
                String IP = "";

                int count = 0;

                if (Relocation)
                {
                    String[] aryIpFormat = IpFormat.Split('.');

                    for (int i = 0; i < aryIpFormat.Length; i++)
                    {
                        if (i == 1)
                        {
                            strIpFormat += "." + aryIpFormat[i].Replace("1", "2");
                        }
                        else if (i == 0)
                        {
                            strIpFormat += aryIpFormat[i];
                        }
                        else
                        {
                            strIpFormat += "." + aryIpFormat[i];
                        }
                    }
                }
                else
                {
                    strIpFormat = IpFormat;
                }

                foreach (char x in strIpFormat)
                {
                    if (x.ToString().ToLower().Equals("x"))
                    {
                        IP += fourDigitStoreNumber[count];
                        count++;
                    }
                    else
                    {
                        IP += x;
                    }
                }

                return(IP);
            }

            return("");
        }
Exemple #2
0
        private void _backgroundWorkerFilterByCountry_DoWork(object sender, DoWorkEventArgs e)
        {
            var lines = File.ReadAllLines(txtFile.Text);

            Invoke(new MethodInvoker(() =>
            {
                btnFile.Enabled   = false;
                btnRun.Enabled    = false;
                button1.Enabled   = false;
                btnFilter.Enabled = false;

                progressBar1.Maximum = lines.Length;

                progressBar1.Value = 0;

                lblStatus.Text = $"{progressBar1.Value}/{progressBar1.Maximum}";
            }));

            _ipRangeResults = null;
            _sshCountries   = new List <SSHCountry>();
            var countries = new List <Country> {
                new Country("", "--All--")
            };

            foreach (var line in lines)
            {
                Invoke(new MethodInvoker(() =>
                {
                    progressBar1.Value++;

                    lblStatus.Text = $"{progressBar1.Value}/{progressBar1.Maximum}";
                }));

                var arr = line.Split('|');

                if (arr.Length < 3)
                {
                    continue;
                }

                var ip   = arr[0];
                var user = arr[1];
                var pass = arr[2];

                var ipFormat = new IpFormat(ip);

                var iplocal =
                    _geoIpCountryList.FirstOrDefault(
                        x => x.IpBegin.Number <= ipFormat.Number && ipFormat.Number <= x.IpEnd.Number);

                var country = "Unknown";
                var isocode = "Unknown";

                if (iplocal != null)
                {
                    country = iplocal.Country.CountryName;
                    isocode = iplocal.Country.ISOCode;

                    if (countries.All(x => x.ISOCode != isocode))
                    {
                        countries.Add(new Country(isocode, country));
                    }
                }

                _sshCountries.Add(new SSHCountry
                {
                    Country = new Country(isocode, country),
                    Ssh     = new SSH
                    {
                        User     = user,
                        Password = pass,
                        Ip       = ip
                    },
                    SshString = line
                });
            }

            countries = countries.OrderBy(x => x.CountryName).ToList();

            countries.Add(new Country("Unknown", "Unknown"));

            Invoke(new MethodInvoker(() =>
            {
                cboCountry.ValueMember   = "ISOCode";
                cboCountry.DisplayMember = "CountryName";

                cboCountry.DataSource = countries;
            }));
        }
Exemple #3
0
 public Boolean IsIPv6()
 {
     return(!IpFormat.Contains("."));
 }