This article covers how to look up mobile carrier information for an IP address using the IPinfo IP to Mobile Carrier API through the official IPinfo C# library.
To get started:
Step 1: Get your access token
You'll need at least the IPinfo core plan. Sign up and copy your IPinfo access token from your dashboard.
IPinfo Core returns an is_mobile boolean flag, while IPinfo Plus and higher plans return a mobile object.
Step 2: Install the IPinfo C# library
Visit our official open-source IPinfo C# library GitHub repo and follow the instructions to install the library.
Step 3: IPinfo C# library ⇒ IP to Mobile Carrier
Depending on your IPinfo plan, you'll need to instantiate the right client and deserialise the response into the right type.
| Plan | Client | Response Type |
|---|---|---|
| Plus | IPinfoClientPlus.Builder() |
IPResponsePlus |
| Core | IPinfoClientCore.Builder() |
IPResponseCore |
Once you have a response object, you can access the fields relevant to your plan.
IPinfo Plus Code Sample
using IPinfo;
using IPinfo.Models;
// Get your IPinfo access token from: https://ipinfo.io/dashboard/token
string token = "TOKEN_GOES_HERE"; // replace with your actual token
// Use CLI args if provided, otherwise fall back to defaults
string[] ips = args.Length > 0
? args
: ["2.120.18.7"];
IPinfoClientPlus client = new IPinfoClientPlus.Builder()
.AccessToken(token)
.Build();
foreach (string ip in ips)
{
Console.WriteLine($"\n{"".PadRight(50, '=')}");
Console.WriteLine($"IP Lookup: {ip}");
Console.WriteLine($"{"".PadRight(50, '=')}");
try{
// making API call
IPResponsePlus ipResponse = await client.IPApi.GetDetailsAsync(ip);
// accessing details from response
Console.WriteLine($"IPResponse.IP: {ipResponse.IP}");
Console.WriteLine($"Mobile Carrier Name: {ipResponse.Mobile.Name}");
Console.WriteLine($"Mobile Country Code: {ipResponse.Mobile.Mcc}");
Console.WriteLine($"Mobile Network Code: {ipResponse.Mobile.Mnc}");
}
catch (Exception ex)
{
Console.WriteLine($"Error looking up {ip}: {ex.Message}");
}
}
Result
==================================================
IP Lookup: 2.120.18.7
==================================================
IPResponse.IP: 2.120.18.7
Mobile Carrier Name: O2 (UK)
Mobile Country Code: 234
Mobile Network Code: 10IPinfo Core Example
using IPinfo;
using IPinfo.Models;
// Get your IPinfo access token from: https://ipinfo.io/dashboard/token
string token = "TOKEN_GOES_HERE"; // replace with your actual token
// Use CLI args if provided, otherwise fall back to defaults
string[] ips = args.Length > 0
? args
: ["2.120.18.7"];
IPinfoClientCore client = new IPinfoClientCore.Builder()
.AccessToken(token)
.Build();
foreach (string ip in ips)
{
Console.WriteLine($"\n{"".PadRight(50, '=')}");
Console.WriteLine($"IP Lookup: {ip}");
Console.WriteLine($"{"".PadRight(50, '=')}");
try{
// making API call
IPResponseCore ipResponse = await client.IPApi.GetDetailsAsync(ip);
// accessing details from response
Console.WriteLine($"IPResponse.IP: {ipResponse.IP}");
Console.WriteLine($"Is Mobile: {ipResponse.IsMobile}");
}
catch (Exception ex)
{
Console.WriteLine($"Error looking up {ip}: {ex.Message}");
}
}
Result
==================================================
IP Lookup: 2.120.18.7
==================================================
IPResponse.IP: 2.120.18.7
Is Mobile: TrueIPinfo Legacy API Sample
Our legacy APIs are fully supported, and existing users can continue to use them. Here's how to use the package with our legacy APIs.
You will need to call the following methods on the IPResponse class variable:
| Code | Description |
|---|---|
| ipResponse.Carrier.Name | Name of the mobile carrier company associated with the IP address |
| ipResponse.Carrier.Mcc | Mobile Country Code (MCC) |
| ipResponse.Carrier.Mnc | Mobile Network Code (MNC) |
Starter code template
using IPinfo;
using IPinfo.Models;
namespace IPinfoApp {
class IPlookup {
static async Task Main(string[] args) {
// initializing IPinfo client
// Get your IPinfo access token from: https://ipinfo.io/dashboard/token
string token = "YOUR_TOKEN";
IPinfoClient client = new IPinfoClient.Builder()
.AccessToken(token)
.Build();
// making the API call
string ip = "174.245.67.12";
IPResponse ipResponse = await client.IPApi.GetDetailsAsync(ip);
// IP to Carrier Insights
Console.WriteLine($"Mobile Carrier Name: {ipResponse.Carrier.Name}");
Console.WriteLine($"Mobile Country Code: {ipResponse.Carrier.Mcc}");
Console.WriteLine($"Mobile Network Code: {ipResponse.Carrier.Mnc}");
}
}
}
Result
Mobile Carrier Name: Verizon
Mobile Country Code: 311
Mobile Network Code: 480
Additional Resources
Mobile carrier data is also available as a downloadable database. See IP to Mobile Carrier database download.
For a broader guide to using C# and .NET with IPinfo, see IP Data and Geolocation in C#: A How-To Guide.