Prerequisites
- A .NET 6+ project with
IpApiIoadded - A free ip-api.io API key
Autonomous system with AsnAsync
Returns the ASN, owning organization, network range, and country for an IP — and whether it belongs to a datacenter. Nullable fields are C# nullable types.
var client = new IpApiClient(Environment.GetEnvironmentVariable("IP_API_IO_KEY")!);
var asn = await client.AsnAsync("8.8.8.8");
Console.WriteLine(asn.Asn); // 15169
Console.WriteLine(asn.Organization); // "Google LLC"
Console.WriteLine(asn.IsDatacenter); // True Domain registration with WhoisAsync
WHOIS record for a domain: registrar, registration/expiry/update dates, name servers, status codes, and the raw WHOIS text.
var whois = await client.WhoisAsync("example.com");
Console.WriteLine(whois.Registrar?.Name);
Console.WriteLine(whois.RegisteredOn); // "1995-08-14"
Console.WriteLine(string.Join(", ", whois.NameServers)); DNS with ReverseDnsAsync, ForwardDnsAsync & MxRecordsAsync
Resolve a PTR record, resolve a hostname to addresses, or list a domain's mail servers.
var rdns = await client.ReverseDnsAsync("8.8.8.8");
Console.WriteLine(rdns.Hostname); // "dns.google"
var fdns = await client.ForwardDnsAsync("dns.google");
foreach (var record in fdns.Addresses)
Console.WriteLine($"{record.Type} {record.Address} {record.Ttl}"); // "A" "8.8.8.8" 300
var mx = await client.MxRecordsAsync("example.com");
foreach (var record in mx.MxRecords)
Console.WriteLine($"{record.Priority} {record.Hostname} {record.Ttl}");