DeviceDetector.NET
4.3.2
See the version list below for details.
dotnet add package DeviceDetector.NET --version 4.3.2
NuGet\Install-Package DeviceDetector.NET -Version 4.3.2
<PackageReference Include="DeviceDetector.NET" Version="4.3.2" />
paket add DeviceDetector.NET --version 4.3.2
#r "nuget: DeviceDetector.NET, 4.3.2"
// Install DeviceDetector.NET as a Cake Addin
#addin nuget:?package=DeviceDetector.NET&version=4.3.2
// Install DeviceDetector.NET as a Cake Tool
#tool nuget:?package=DeviceDetector.NET&version=4.3.2
DeviceDetector.NET
Description
The Universal Device Detection library for .NET that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, feed readers, media players, PIMs, ...), operating systems, brands and models. This is a port of the popular PHP device-detector library to C#. For the most part you can just follow the documentation for device-detector with no issue.
Usage
Using DeviceDetector.NET with nuget is quite easy. Just add DeviceDetector.NET to your projects requirements. And use some code like this one:
using DeviceDetectorNET;
// OPTIONAL: Set version truncation to none, so full versions will be returned
// By default only minor versions will be returned (e.g. X.Y)
// for other options see VERSION_TRUNCATION_* constants in DeviceParserAbstract class
// add using DeviceDetectorNET.Parser;
DeviceDetector.SetVersionTruncation(VersionTruncation.VERSION_TRUNCATION_NONE);
var dd = new DeviceDetector(userAgent);
// OPTIONAL: Set caching method
// By default static cache is used, which works best within one php process (memory array caching)
// To cache across requests use caching in files or memcache
// add using DeviceDetectorNET.Cache;
dd.SetCache(new DictionaryCache());
// OPTIONAL: If called, GetBot() will only return true if a bot was detected (speeds up detection a bit)
dd.DiscardBotInformation();
// OPTIONAL: If called, bot detection will completely be skipped (bots will be detected as regular devices then)
dd.SkipBotDetection();
dd.Parse();
if(dd.IsBot()) {
// handle bots,spiders,crawlers,...
var botInfo = dd.GetBot();
} else {
var clientInfo = dd.GetClient(); // holds information about browser, feed reader, media player, ...
var osInfo = dd.GetOs();
var device = dd.GetDeviceName();
var brand = dd.GetBrandName();
var model = dd.GetModel();
}
Instead of using the full power of DeviceDetector it might in some cases be better to use only specific parsers. If you aim to check if a given useragent is a bot and don't require any of the other information, you can directly use the bot parser.
using DeviceDetectorNET.Parser;
var botParser = new BotParser();
botParser.SetUserAgent(userAgent);
// OPTIONAL: discard bot information. Parse() will then return true instead of information
botParser.DiscardDetails = true;
var result = botParser.Parse();
if (result != null) {
// do not do anything if a bot is detected
return;
}
// handle non-bot requests
The default regexes directory path can be changed like this:
DeviceDetectorSettings.RegexesDirectory = @"C:\YamlRegexsFiles\";
.....
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
.NET Core | netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.0 netstandard2.1 |
.NET Framework | net461 net462 net463 net47 net471 net472 net48 net481 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETFramework 4.6.1
- LiteDB (>= 5.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
- Newtonsoft.Json (>= 13.0.1)
- semver (>= 2.0.6)
- YamlDotNet (>= 11.2.1)
-
.NETStandard 2.0
- LiteDB (>= 5.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
- Newtonsoft.Json (>= 13.0.1)
- semver (>= 2.0.6)
- YamlDotNet (>= 11.2.1)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on DeviceDetector.NET:
Package | Downloads |
---|---|
OneLine
OneLine is an abstraction standardized redefined framework. |
|
H.Necessaire.Runtime
A Core Framework for Rapid Application Development |
|
OneLine.Common
OneLine.Common is a project that can be used on a server backend as well on client side application that support net standard like xamarin or blazor. |
|
uMarketingSuite.Core
The all-in-one marketing solution for the Umbraco CMS - assemblies only |
|
Yaroslav08.Extensions
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
6.1.0 | 3,290 | 3/5/2023 |
4.3.2 | 43,956 | 10/24/2022 |
4.3.1 | 250 | 10/24/2022 |
4.3.0 | 525,583 | 8/8/2021 |
4.2.0 | 374,818 | 7/26/2020 |
4.1.0 | 258,410 | 8/26/2019 |
4.0.0 | 22,366 | 7/5/2019 |
3.11.6 | 14,402 | 4/25/2019 |
3.11.4 | 54,014 | 12/31/2018 |
3.11.2 | 9,360 | 11/4/2018 |
3.9.2.2 | 18,451 | 2/28/2018 |
3.9.2.1 | 976 | 2/28/2018 |
3.9.2 | 1,093 | 2/9/2018 |
3.9.1 | 915 | 2/1/2018 |
3.8.1 | 1,385 | 1/29/2018 |