libloc 1.1.0

dotnet add package libloc --version 1.1.0                
NuGet\Install-Package libloc -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="libloc" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add libloc --version 1.1.0                
#r "nuget: libloc, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install libloc as a Cake Addin
#addin nuget:?package=libloc&version=1.1.0

// Install libloc as a Cake Tool
#tool nuget:?package=libloc&version=1.1.0                

libloc-sharp

DragonFruit Discord GitHub Latest Release)

A version of IPFire's libloc library rewritten for .NET

Overview

This is a rewritten version of libloc (an IP address database used by IPFire firewall software to screen network traffic) along with an additional library, libloc.Access, that enables the database to be loaded as a hosted service, enabling automatic database updates and access control.

The core libloc project has been written to require a single 3rd party library (IPNetwork) and has most of the expected read functionality.

Usage (libloc)

Latest Nuget

The libloc DatabaseLoader.LoadFromFile(string path) returns an ILocationDatabase if the database was successfully loaded in. Accessing different features of the database can then be done through this instance:

  • ILocationDatabase.AS provides a database of Autonomous Systems, where the entire collection can be accessed, or a specific entry can be loaded by ASN
  • ILocationDatabase.Networks provides all networks that own a block of IP addresses which can be accessed by index or enumerated over
  • ILocationDatabase.Countries provides a list of all countries and their continents. These can be accessed by country code, index or enumerated over
  • ILocationDatabase.ResolveAddress(IPAddress address) performs a network tree traversal to locate the network a specific address belongs to, along with the ASN of the owner, the start and end addresses and the prefix length. These values are stored and processed as IPv6, so an IPv4 address will need mapping back from v6 if desired.
  • ILocationDatabase.GetEnumerator(AddressFamily family) provides an enumerator that can be used to get all networks, and their corresponding address blocks.
var database = DatabaseLoader.LoadFromFile("C:\location.db");

// locate 1.1.1.1
var networkInfo = database.ResolveAddress(IPAddress.Parse("1.1.1.1"));

// load AS info
var asInfo = database.AS[networkInfo.ASN];

Usage (libloc.Access)

Latest Nuget (libloc.Access)

There are a few things to note when using libloc.Access:

  • A DragonFruit.Data.ApiClient must be registered in the dependency container - see here for more information
  • IConfiguration is used to load service preferences in (under the LocationDb section)
  • ILogger is injected into the database accessor for logging and diagnosing the database update process

To use the database accessor, use builder.Services.AddLocationDb() in the startup code (after the client has been registered) and access the database using the ILocationDbAccessor interface:

builder.Serivces.AddSingleton<ApiClient<ApiSystemTextJsonSerializer>>();

// add databases
builder.Services.AddLocationDb();
builder.Services.AddDbContext<DummyDatabase>(c => c.UseNpgsql("Host=localhost"));

// after building the host, you can access the database via dependency injection
var locationDb = services.GetRequiredService<ILocationDbAccessor>();
var network = await locationDb.PerformAsync(db => db.ResolveNetwork(IPAddress.Parse("1.1.1.1")));

License

The project is licensed under LGPL-2.1, the same as the original library.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on libloc:

Package Downloads
libloc.Access

Automated database management for libloc library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 128 9/27/2024