Ip2Asn 1.0.0

dotnet add package Ip2Asn --version 1.0.0
                    
NuGet\Install-Package Ip2Asn -Version 1.0.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="Ip2Asn" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ip2Asn" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Ip2Asn" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ip2Asn --version 1.0.0
                    
#r "nuget: Ip2Asn, 1.0.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.
#:package Ip2Asn@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ip2Asn&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Ip2Asn&version=1.0.0
                    
Install as a Cake Tool

Ip2Asn

Offline IP → ASN lookup for .NET. Point it at an iptoasn.com TSV dump and resolve any IPv4 or IPv6 address to its AS number, country and AS name. No API keys, no network calls, no rate limits.

dotnet add package Ip2Asn

Get the data

Download ip2asn-combined.tsv.gz from iptoasn.com (covers IPv4 + IPv6). .gz files work as-is — no need to unpack.

Use it

using Ip2Asn;

// Load once at start-up, then reuse. Thread-safe for concurrent lookups.
var db = Ip2AsnDatabase.LoadFromTsv("ip2asn-combined.tsv");

if (db.TryLookup("142.250.199.132", out AsnRecord record))
{
    Console.WriteLine(record.Asn);          // 15169
    Console.WriteLine(record.CountryCode);  // US
    Console.WriteLine(record.Description);  // GOOGLE
    Console.WriteLine(record.RangeStart);   // 142.250.199.0
    Console.WriteLine(record.RangeEnd);     // 142.250.199.255
}

Other ways to ask:

uint? asn = db.GetAsn("142.250.199.132");           // 15169, or null
AsnRecord? hit = db.Lookup(IPAddress.Parse("1.1.1.1"));

Bulk

// A whole batch at once — large batches are spread across cores.
AsnLookupResult[] results = db.LookupBatch(logRows.Select(r => r.VisitedIp).ToList());

foreach (var r in results)
    Console.WriteLine($"{r.Input} -> {(r.Found ? "AS" + r.Record.Asn : "unknown")}");

// Or stream, for input too big to hold in memory.
foreach (var r in db.LookupMany(File.ReadLines("ips.txt")))
    Console.WriteLine($"{r.Input}\t{r.Asn}");

Accepted input

All of these resolve to the same answer — a port, CIDR prefix, zone id, brackets or surrounding whitespace are ignored:

142.250.199.132        142.250.199.132:443     142.250.199.132/24
::ffff:142.250.199.132   2606:4700::1          [2606:4700::1]:443
2606:4700::1/48        2606:4700::1%eth0        " 2606:4700::1 "

Unknown addresses

TryLookup returns false (and GetAsn returns null) both for input that isn't an address and for addresses nobody announces — private ranges like 10.250.14.7, reserved and unallocated space.

To tell those two apart, keep the dataset's "not routed" rows:

var db = Ip2AsnDatabase.LoadFromTsv("ip2asn-combined.tsv",
    new Ip2AsnOptions { SkipUnroutedRanges = false });

if (!db.TryLookup(ip, out AsnRecord r))  Console.WriteLine("not a valid IP");
else if (!r.IsRouted)                    Console.WriteLine("private / not routed");
else                                     Console.WriteLine($"AS{r.Asn} {r.Description}");

Faster start-up

Loading the 45 MB TSV takes ~380 ms. Convert it once to a binary index and load that instead:

Ip2AsnDatabase.LoadFromTsv("ip2asn-combined.tsv").SaveIndex("ip2asn.bin");

var db = Ip2AsnDatabase.LoadIndex("ip2asn.bin");   // ~155 ms, 15 MB file

ASP.NET Core

builder.Services.AddSingleton<IIp2AsnLookup>(
    _ => Ip2AsnDatabase.LoadFromTsv("ip2asn-combined.tsv"));

Options

Option Default
SkipUnroutedRanges true Drop the dataset's AS 0 "not routed" rows.
ThrowOnMalformedLines false Throw Ip2AsnFormatException instead of skipping a bad line.

Also available: LoadFromTsvAsync, LoadFromTsv(Stream), LoadFromTsv(TextReader), and Count / IPv4RangeCount / IPv6RangeCount / SkippedLineCount.

Numbers

Full ip2asn-combined.tsv (717k rows), .NET 8, one core unless noted:

Load from TSV 380 ms
Load from binary index 155 ms
Memory ~24 MB
Lookups 4.9 M/s
LookupBatch 13 M/s (all cores)

Try it

dotnet run --project samples/Ip2Asn.Sample -- ip2asn-combined.tsv 1.1.1.1 8.8.8.8:443
cat ips.txt | dotnet run --project samples/Ip2Asn.Sample -- ip2asn-combined.tsv

Targets netstandard2.0 and net8.0. MIT licensed. The ip2asn dataset itself is published by iptoasn.com under its own terms and is not redistributed here.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 104 9/2/2026

First release. Offline IPv4/IPv6 to ASN lookup from an iptoasn.com TSV dump: single and bulk lookups, tolerant input parsing (ports, CIDR, brackets, zone ids, IPv4-mapped), an optional prebuilt binary index for faster start-up, and no network calls.