예제 #1
0
 private void prepareIp(DataRow _row)
 {
     ipAddress.IpClassification     = UdgerParser.ConvertToStr(_row["ip_classification"]);
     ipAddress.IpClassificationCode = UdgerParser.ConvertToStr(_row["ip_classification_code"]);
     ipAddress.IpLastSeen           = UdgerParser.ConvertToStr(_row["ip_last_seen"]);
     ipAddress.IpHostname           = UdgerParser.ConvertToStr(_row["ip_hostname"]);
     ipAddress.IpCountry            = UdgerParser.ConvertToStr(_row["ip_country"]);
     ipAddress.IpCountryCode        = UdgerParser.ConvertToStr(_row["ip_country_code"]);
     ipAddress.IpCity                      = UdgerParser.ConvertToStr(_row["ip_city"]);
     ipAddress.CrawlerName                 = UdgerParser.ConvertToStr(_row["name"]);
     ipAddress.CrawlerVer                  = UdgerParser.ConvertToStr(_row["ver"]);
     ipAddress.CrawlerVerMajor             = UdgerParser.ConvertToStr(_row["ver_major"]);
     ipAddress.CrawlerFamily               = UdgerParser.ConvertToStr(_row["family"]);
     ipAddress.CrawlerFamilyCode           = UdgerParser.ConvertToStr(_row["family_code"]);
     ipAddress.CrawlerFamilyHomepage       = UdgerParser.ConvertToStr(_row["family_homepage"]);
     ipAddress.CrawlerFamilyVendor         = UdgerParser.ConvertToStr(_row["vendor"]);
     ipAddress.CrawlerFamilyVendorCode     = UdgerParser.ConvertToStr(_row["vendor_code"]);
     ipAddress.CrawlerFamilyVendorHomepage = UdgerParser.ConvertToStr(_row["vendor_homepage"]);
     ipAddress.CrawlerFamilyIcon           = UdgerParser.ConvertToStr(_row["family_icon"]);
     ipAddress.CrawlerLastSeen             = UdgerParser.ConvertToStr(_row["last_seen"]);
     ipAddress.CrawlerCategory             = UdgerParser.ConvertToStr(_row["crawler_classification"]);
     ipAddress.CrawlerCategoryCode         = UdgerParser.ConvertToStr(_row["crawler_classification_code"]);
     if (ipAddress.IpClassificationCode == "crawler")
     {
         ipAddress.CrawlerFamilyInfoUrl = "https://udger.com/resources/ua-list/bot-detail?bot=" + UdgerParser.ConvertToStr(_row["family"]) + "#id" + UdgerParser.ConvertToStr(_row["botid"]);
     }
     ipAddress.CrawlerRespectRobotstxt = UdgerParser.ConvertToStr(_row["respect_robotstxt"]);
 }
예제 #2
0
        static void Main(string[] args)
        {
            // create a new UdgerParser object
            UdgerParser parser = new UdgerParser(true);  // Development/Debug - debug info output to console
            //UdgerParser parser = new UdgerParser(); // Production

            // set data dir (this program must right write to cache dir)
            parser.SetDataDir(@"C:\tmp");

            // set You Accesskey (see https://udger.com/account/main) 
            //parser.SetAccessKey("XXXXXX");
            // or download the datafile manually from http://data.udger.com/
            
            //If you want information about fragments
            parser.SetParseFragments(false); //for future use, now has no meaning


            //method "parse"
            var useragent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; de) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/8888 Chrome anonymized by Abelssoft 1085275131";
            // Gets information about the user agent
            Dictionary<string, object> aa = parser.parse(useragent);

            //method "isBot"
            useragent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
            //var ip = "100.43.81.130";
            Dictionary<string, object> bb = parser.isBot(useragent);
            useragent = "Mozilla/4.0 (compatible; MSIE ; Windows NT 6.0)";
            bb = parser.isBot(useragent);

            //method "account"
            Dictionary<string, object> cc = parser.account();
            

        }
예제 #3
0
        static void Main(string[] args)
        {            

            Udger.Parser.UserAgent a;
            Udger.Parser.IPAddress i;

            // Create a new UdgerParser object
            UdgerParser parser = new UdgerParser();

            // Set data dir (in this directory is stored data file: udgerdb_v3.dat)
            // Data file can be downloaded manually from http://data.udger.com/, but we recommend use udger-updater
            parser.SetDataDir(@"C:\udger");
            //parser.SetDataDir(@"C:\udger", "udgerdb_v3-noip.dat ");

            // Set user agent and /or IP address
            parser.ua = @"Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13E238";
            parser.ip = "108.61.199.93";
            
            // Parse
            parser.parse();
            // Get information 
            a = parser.userAgent;
            i = parser.ipAddress;

            
            parser.ua = @"Mozilla/5.0 (compatible; SeznamBot/3.2; +http://fulltext.sblog.cz/)";
            parser.ip = "2001:41d0:8:d950:0:0:0:1";
            parser.parse();
            a = parser.userAgent;            
            i = parser.ipAddress;

                        
            parser.ua = @"'&lorem>>'adasdad asd ";
            parser.ip = "lorem'bla?&";
            parser.parse();
            a = parser.userAgent;
            i = parser.ipAddress;

            parser.ua = @"Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53";
            parser.ip = "2001:41d0:8:d950::1";
            parser.parse();
            a = parser.userAgent;
            i = parser.ipAddress;

            
            parser.ip = "66.249.64.73";
            parser.parse();
            a = parser.userAgent;
            i = parser.ipAddress;

           
            parser.ua = @"Mozilla/5.0 (Playstation Vita 1.61) AppleWebKit/531.22.8 (KHTML, like Gecko) Silk/3.2";
            parser.ip = "90.177.52.111";
            parser.parse();
            a = parser.userAgent;
            i = parser.ipAddress;
            
        }
예제 #4
0
 private void prepareDevice(DataRow _row, ref int _deviceClassId)
 {
     _deviceClassId               = Convert.ToInt32(_row["deviceclass_id"]);
     userAgent.DeviceClass        = UdgerParser.ConvertToStr(_row["name"]);
     userAgent.DeviceClassCode    = UdgerParser.ConvertToStr(_row["name_code"]);
     userAgent.DeviceClassIcon    = UdgerParser.ConvertToStr(_row["icon"]);
     userAgent.DeviceClassIconBig = UdgerParser.ConvertToStr(_row["icon_big"]);
     userAgent.DeviceClassInfoUrl = "https://udger.com/resources/ua-list/device-detail?device=" + UdgerParser.ConvertToStr(_row["name"]);
 }
예제 #5
0
        private void parseIP(string _ip)
        {
            string ipLoc;

            if (!string.IsNullOrEmpty(_ip))
            {
                ipAddress.Ip = this.ip;

                if (dt.Connected)
                {
                    int ipVer = this.getIPAddressVersion(ip, out ipLoc);
                    if (ipVer != 0)
                    {
                        if (ipLoc != "")
                        {
                            _ip = ipLoc;
                        }

                        ipAddress.IpVer = UdgerParser.ConvertToStr(ipVer);

                        DataTable ipTable = dt.selectQuery(@"SELECT udger_crawler_list.id as botid,ip_last_seen,ip_hostname,ip_country,ip_city,ip_country_code,ip_classification,ip_classification_code,
                                          name,ver,ver_major,last_seen,respect_robotstxt,family,family_code,family_homepage,family_icon,vendor,vendor_code,vendor_homepage,crawler_classification,crawler_classification_code,crawler_classification
                                          FROM udger_ip_list
                                          JOIN udger_ip_class ON udger_ip_class.id=udger_ip_list.class_id
                                          LEFT JOIN udger_crawler_list ON udger_crawler_list.id=udger_ip_list.crawler_id
                                          LEFT JOIN udger_crawler_class ON udger_crawler_class.id=udger_crawler_list.class_id
                                          WHERE ip=" + '"' + _ip + '"' + " ORDER BY sequence");

                        if (ipTable != null && ipTable.Rows.Count > 0)
                        {
                            this.prepareIp(ipTable.Rows[0]);
                        }
                        if (ipVer == 4)
                        {
                            long ipLong = this.AddrToInt(_ip);//ip2Long.Address;

                            DataTable dataCenter = dt.selectQuery(@"select name, name_code, homepage
                                       FROM udger_datacenter_range
                                       JOIN udger_datacenter_list ON udger_datacenter_range.datacenter_id = udger_datacenter_list.id
                                       where iplong_from <= " + ipLong.ToString() + " AND iplong_to >=" + ipLong.ToString());

                            if (dataCenter != null && dataCenter.Rows.Count > 0)
                            {
                                this.prepareIpDataCenter(dataCenter.Rows[0]);
                            }
                        }
                    }
                }
            }
        }
예제 #6
0
 private void prepareOs(DataRow _row, ref int _osId)
 {
     _osId                            = Convert.ToInt32(_row["os_id"]);
     userAgent.Os                     = UdgerParser.ConvertToStr(_row["name"]);
     userAgent.OsCode                 = UdgerParser.ConvertToStr(_row["name_code"]);
     userAgent.OsHomepage             = UdgerParser.ConvertToStr(_row["homepage"]);
     userAgent.OsIcon                 = UdgerParser.ConvertToStr(_row["icon"]);
     userAgent.OsIconBig              = UdgerParser.ConvertToStr(_row["icon_big"]);
     userAgent.OsInfoUrl              = "https://udger.com/resources/ua-list/os-detail?os=" + UdgerParser.ConvertToStr(_row["name"]);
     userAgent.OsFamily               = UdgerParser.ConvertToStr(_row["family"]);
     userAgent.OsFamilyCode           = UdgerParser.ConvertToStr(_row["family_code"]);
     userAgent.OsFamilyVendor         = UdgerParser.ConvertToStr(_row["vendor"]);
     userAgent.OsFamilyVendorCode     = UdgerParser.ConvertToStr(_row["vendor_code"]);
     userAgent.OsFamilyVendorHomepage = UdgerParser.ConvertToStr(_row["vendor_homepage"]);
 }
예제 #7
0
 public void connect(UdgerParser _udger)
 {
     udger = _udger;
     try
     {
         if (!this.Connected)
         {
             sqlite         = new SQLiteConnection(@"Data Source=" + DataSourcePath);
             this.connected = true;
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
예제 #8
0
 public void connect(UdgerParser _udger)
 {
     udger = _udger;
     try
     { 
         if (!this.Connected)
         {                   
             sqlite = new SQLiteConnection(@"Data Source=" + DataSourcePath);
             this.connected = true;
             
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
예제 #9
0
 private void prepareCrawler(DataRow _row)
 {
     userAgent.UaClass                 = "Crawler";
     userAgent.UaClassCode             = "crawler";
     userAgent.Ua                      = UdgerParser.ConvertToStr(_row["name"]);
     userAgent.UaVersion               = UdgerParser.ConvertToStr(_row["ver"]);
     userAgent.UaVersionMajor          = UdgerParser.ConvertToStr(_row["ver_major"]);
     userAgent.UaFamily                = UdgerParser.ConvertToStr(_row["family"]);
     userAgent.UaFamilyCode            = UdgerParser.ConvertToStr(_row["family_code"]);
     userAgent.UaFamilyHompage         = UdgerParser.ConvertToStr(_row["family_homepage"]);
     userAgent.UaFamilyVendor          = UdgerParser.ConvertToStr(_row["vendor"]);
     userAgent.UaFamilyVendorCode      = UdgerParser.ConvertToStr(_row["vendor_code"]);
     userAgent.UaFamilyVendorCode      = UdgerParser.ConvertToStr(_row["vendor_homepage"]);
     userAgent.UaFamilyIcon            = UdgerParser.ConvertToStr(_row["family_icon"]);
     userAgent.UaFamilyIconUrl         = "https://udger.com/resources/ua-list/bot-detail?bot=" + UdgerParser.ConvertToStr(_row["family"]) + "#id" + UdgerParser.ConvertToStr(_row["botid"]);
     userAgent.CrawlerLastSeen         = UdgerParser.ConvertToStr(_row["last_seen"]);
     userAgent.CrawlerCategory         = UdgerParser.ConvertToStr(_row["crawler_classification"]);
     userAgent.CrawlerCategoryCode     = UdgerParser.ConvertToStr(_row["crawler_classification_code"]);
     userAgent.CrawlerRespectRobotstxt = UdgerParser.ConvertToStr(_row["respect_robotstxt"]);
 }
예제 #10
0
 private void prepareClientRegex(DataRow _row, System.Text.RegularExpressions.Match _match, ref int _clienId, ref int _clientClassId)
 {
     _clienId              = Convert.ToInt32(_row["client_id"]);
     _clientClassId        = Convert.ToInt32(_row["class_id"]);
     userAgent.UaString    = this.ua;
     userAgent.UaClass     = UdgerParser.ConvertToStr(_row["client_classification"]);//ToString();
     userAgent.UaClassCode = UdgerParser.ConvertToStr(_row["client_classification_code"]);
     userAgent.Ua          = UdgerParser.ConvertToStr(_row["name"]) + _match.Groups[1].Value;
     userAgent.UaVersion   = _match.Groups[1].Value;
     string[] spliter = _match.Groups[1].Value.Split('.');
     userAgent.UaVersionMajor           = spliter[0];
     userAgent.UaUptodateCurrentVersion = UdgerParser.ConvertToStr(_row["uptodate_current_version"]);
     userAgent.UaFamily               = UdgerParser.ConvertToStr(_row["name"]);
     userAgent.UaFamilyCode           = UdgerParser.ConvertToStr(_row["name_code"]);
     userAgent.UaFamilyHompage        = UdgerParser.ConvertToStr(_row["homepage"]);
     userAgent.UaFamilyVendor         = UdgerParser.ConvertToStr(_row["vendor"]);
     userAgent.UaFamilyVendorCode     = UdgerParser.ConvertToStr(_row["vendor_code"]);
     userAgent.UaFamilyVendorHomepage = UdgerParser.ConvertToStr(_row["vendor_homepage"]);
     userAgent.UaFamilyIcon           = UdgerParser.ConvertToStr(_row["icon"]);
     userAgent.UaFamilyIconBig        = UdgerParser.ConvertToStr(_row["icon_big"]);
     userAgent.UaFamilyIconUrl        = "https://udger.com/resources/ua-list/browser-detail?browser=" + UdgerParser.ConvertToStr(_row["name"]);
     userAgent.UaEngine               = UdgerParser.ConvertToStr(_row["engine"]);
 }
예제 #11
0
 private void prepareIpDataCenter(DataRow _row)
 {
     ipAddress.DatacenterName     = UdgerParser.ConvertToStr(_row["name"]);
     ipAddress.DatacenterNameCode = UdgerParser.ConvertToStr(_row["name_code"]);
     ipAddress.DatacenterHomepage = UdgerParser.ConvertToStr(_row["homepage"]);
 }
예제 #12
0
        public void connect(UdgerParser _udger)
        {
            udger = _udger;
            try
            {
                if (!Directory.Exists(data_dir))
                {
                    throw new Exception("Data dir not found");
                }

                if (!this.Connected)
                {
                    udger.WriteDebug("Open DB file: " + DataSourcePath);
                    if (!string.IsNullOrEmpty(this.access_key))
                    {
                        if (File.Exists(DataSourcePath))
                        {
                            sqlite         = new SQLiteConnection(@"Data Source=" + DataSourcePath);
                            this.connected = true;
                            if (sqlite != null)
                            {
                                DataTable _info_ = this.selectQuery("SELECT lastupdate,version FROM _info_ where key=1");
                                if (_info_.Rows.Count > 0)
                                {
                                    DataRow row        = _info_.Rows[0];
                                    long    time       = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
                                    long    lastUpdate = Convert.ToInt32(row["lastupdate"].ToString());

                                    if (lastUpdate + this.updateInteval < time)
                                    {
                                        udger.WriteDebug("Data is maybe outdated, check new data from server");
                                        this.downloadFile(row["version"].ToString());
                                    }
                                    else
                                    {
                                        udger.WriteDebug("Data is current and will be used");
                                    }
                                }
                                else
                                {
                                    udger.WriteDebug("Data is corrupted, download data");
                                    this.downloadFile();
                                }
                            }
                        }
                        else
                        {
                            udger.WriteDebug("Data dir is empty, download data");
                            this.downloadFile();
                        }
                    }
                    if (File.Exists(DataSourcePath))
                    {
                        sqlite         = new SQLiteConnection(@"Data Source=" + DataSourcePath);
                        this.connected = true;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #13
0
        public void connect(UdgerParser _udger)
        {
            udger = _udger;
            try
            {
                if (!Directory.Exists(data_dir))
                    throw new Exception("Data dir not found");

                if (!this.Connected)
                {
                    udger.WriteDebug("Open DB file: " + DataSourcePath);
                    if (!string.IsNullOrEmpty(this.access_key))                    
                    {
                        if (File.Exists(DataSourcePath))
                        {
                            sqlite = new SQLiteConnection(@"Data Source=" + DataSourcePath);
                            this.connected = true;
                            if (sqlite != null)
                            {
                                DataTable _info_ = this.selectQuery("SELECT lastupdate,version FROM _info_ where key=1");
                                if (_info_.Rows.Count > 0)
                                {                                    
                                    DataRow row = _info_.Rows[0];
                                    long time = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
                                    long lastUpdate = Convert.ToInt32(row["lastupdate"].ToString());
                                
                                    if (lastUpdate + this.updateInteval < time)
                                    {
                                        udger.WriteDebug("Data is maybe outdated, check new data from server");
                                        this.downloadFile(row["version"].ToString());
                                    }
                                    else
                                    {
                                        udger.WriteDebug("Data is current and will be used");
                                    }                                    
                                }
                                else
                                {
                                    udger.WriteDebug("Data is corrupted, download data");
                                    this.downloadFile();
                                }

                            }
                        }
                        else {
                            udger.WriteDebug("Data dir is empty, download data");
                            this.downloadFile();
                        }
                    }
                    if (File.Exists(DataSourcePath))
                    {
                        sqlite = new SQLiteConnection(@"Data Source=" + DataSourcePath);
                        this.connected = true;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }