Dotnet
Official C# client library for the ipdata API
IPData Dotnet Library
ipdata.co is a fast, reliable and clean service that allows you to look up the location of an IP Address and other data.
Table of Content
Install
NuGet package install using package manager:
Install-Package IpData -Version 2.0.1
NuGet package install using .NET CLI:
dotnet add package IpData --version 2.0.1
Lookup
All usage examples you can find on samples
folder.
Basic
var client = new IpDataClient("<<apiKey>>");
// Get IP data from my IP
var myIpInfo = await client.Lookup();
Console.WriteLine($"Country name for {myIpInfo.Ip} is {myIpInfo.CountryName}");
// Get IP data from IP
var ipInfo = await client.Lookup("8.8.8.8");
Console.WriteLine($"Country name for {ipInfo.Ip} is {ipInfo.CountryName}");
// Get single field from IP
var countryName = await client.Lookup("8.8.8.8", x => x.CountryName);
Console.WriteLine($"Country name for 8.8.8.8 is {countryName}");
// Get multiple fields from IP
var geolocation = await client.Lookup("8.8.8.8", x => x.Latitude, x => x.Longitude);
Console.WriteLine($"Geolocation for 8.8.8.8 is lat: {geolocation.Latitude} long: {geolocation.Longitude}");
Bulk
From ipdata.co docs:
Note that bulk lookups are only available to paid users and are currently limited to a 100 at a time. Reach out to support if you need to lookup larger batches.
var client = new IpDataClient("<<apiKey>>");
var ipInfoList = await client.Lookup(new string[] { "1.1.1.1", "2.2.2.2", "3.3.3.3" });
foreach (var ipInfo in ipInfoList)
{
Console.WriteLine($"Country name for {ipInfo.Ip} is {ipInfo.CountryName}");
}
Carrier
var client = new IpDataClient("<<apiKey>>");
var carrierInfo = await client.Carrier("69.78.70.144");
Console.WriteLine($"Carrier name: {carrierInfo.Name}");
ASN
var client = new IpDataClient("<<apiKey>>");
var asnInfo = await client.Asn("69.78.70.144");
Console.WriteLine($"ASN name: {asnInfo.Name}");
Timezone
var client = new IpDataClient("<<apiKey>>");
var timezoneInfo = await client.TimeZone("69.78.70.144");
Console.WriteLine($"TimeZone name: {timezoneInfo.Name}");
Currency
var client = new IpDataClient("<<apiKey>>");
var currencyInfo = await client.Currency("69.78.70.144");
Console.WriteLine($"Currency name: {currencyInfo.Name}");
Threat
var client = new IpDataClient("<<apiKey>>");
var threatInfo = await client.Threat("69.78.70.144");
Console.WriteLine($"Threat is Tor: {threatInfo.IsTor}");
Contributing
Please read [CONTRIBUTING.md][CONTRIBUTING] for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use [SemVer] for versioning. For the versions available, see the tags on this repository.
License
This project is licensed under the MIT License - see the [LICENSE.md][LICENSE] file for details
[AzureStatus]: https://dev.azure.com/alexkhildev/IpData/_apis/build/status/gated?branchName=master[IpDataLogo]: https://image.ibb.co/iDQdUS/ipdatalogo.png[SemVer]: http://semver.org/[CONTRIBUTING]: https://github.com/alexkhil/IpData/blob/master/.github/CONTRIBUTING.md[LICENSE]: https://github.com/alexkhil/IpData/blob/master/LICENSE
Updated over 2 years ago