예제 #1
0
        public static void Add(GeoData ipData)
        {
            using (SQLiteConnection connection = new SQLiteConnection(connBuilder.ToString()))
            {
                connection.Open();

                long longIP = IpUtilities.IpToUint(ipData.IpAddress);
                long subnet24 = longIP - (longIP % 256);
                long idx = longIP - (longIP % 65536);

                string query = string.Format(@"INSERT INTO [subnets] ([subnet], [country], [city], [carrier], [org], [ccode], [state], [sld], [idx])
                VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}' )",
                    subnet24,
                    ipData.Country,
                    ipData.City,
                    ipData.Carrier,
                    ipData.Organisation,
                    ipData.CountryCode,
                    ipData.State,
                    ipData.Sld,
                    idx);

                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    command.CommandText = query;
                    command.CommandType = CommandType.Text;
                    command.ExecuteNonQuery();
                }
            }
        }
예제 #2
0
        public GeoData Get()
        {
            if (IpUtilities.IsReservedIP(_ip))
            {
                return null;
            }

            geodata = RamCache.Get(_ip);
            if (geodata != null)
            {
                return geodata;
            }

            geodata = SQLiteCache.Get(_ip);
            if (geodata != null)
            {
                RamCache.Add(geodata);
                return geodata;
            }

            string api = File.ReadAllLines("api+secret")[0].Split('|')[0];
            string secret = File.ReadAllLines("api+secret")[0].Split('|')[1];
            Quova q = new Quova(api, secret);
            IpInfo ipInfo = q.LookUp(_ip);
            if (ipInfo != null)
            {
                geodata = new GeoData()
                {
                    IpAddress = _ip,
                    Country = ipInfo.Location.CountryData.country,
                    City = ipInfo.Location.CityData.city,
                    Organisation = ipInfo.Network.organization,
                    Carrier = ipInfo.Network.carrier,
                    CountryCode = ipInfo.Location.CountryData.country_code,
                    State = ipInfo.Location.StateData.state,
                    Sld = ipInfo.Network.Domain.sld
                };
                RamCache.Add(geodata);
                SQLiteCache.Add(geodata);
                return geodata;
            }

            return null;
        }
예제 #3
0
        public static void Add(GeoData data)
        {
            GeoData geoDataToDict = (GeoData) data.Clone();

            /*
             for example:
             ipData.IPAddress: 255.101.18.34
             long longIp: 4284813858
             ip_address 24 mask is a IPCache key: 255.101.18.0
            */

            uint longIp = IpUtilities.IpToUint(geoDataToDict.IpAddress);
            IPAddress subnet24 = IpUtilities.UintToIp(longIp - (longIp % 256));
            geoDataToDict.IpAddress = subnet24;
            try
            {
                IPCache.Add(subnet24, geoDataToDict);
            }
            catch
            {
            }
        }
 public BatchWindowListViewView(GeoData ipdata, string clipdata)
 {
     _ipdata = (GeoData)ipdata.Clone();
     _clipdata = clipdata;
 }
예제 #5
0
        public static GeoData Get(IPAddress ip)
        {
            using (SQLiteConnection connection = new SQLiteConnection(connBuilder.ToString()))
            {
                connection.Open();

                long longIP = IpUtilities.IpToUint(ip);
                long subnet24 = longIP - (longIP % 256);

                string query = string.Format(@"SELECT * FROM [subnets] WHERE idx = ({0} - ({0} % 65536)) AND subnet = '{0}'", subnet24);

                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    command.CommandText = query;
                    command.CommandType = CommandType.Text;
                    SQLiteDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        DataTable dt = new DataTable();
                        dt.Load(reader);

                        GeoData ipData = new GeoData();
                        ipData.IpAddress = ip;
                        ipData.Country = dt.Rows[0].Field<string>("country");
                        ipData.City = dt.Rows[0].Field<string>("city");
                        ipData.Carrier = dt.Rows[0].Field<string>("carrier");
                        ipData.Organisation = dt.Rows[0].Field<string>("org");
                        ipData.CountryCode = dt.Rows[0].Field<string>("ccode");
                        ipData.State = dt.Rows[0].Field<string>("state");
                        ipData.Sld = dt.Rows[0].Field<string>("sld");
                        return ipData;
                    }
                }
            }
            return null;
        }