This is a library that checks the external IP address of a running PC, acquires a wildcard domain, and searches IP band information.
$ dotnet add package ReflectionIPAddressThis is a library that checks the external IP address of a running PC, acquires a wildcard domain, and searches IP band information.
This library implements the simultaneous queries of several free services (e.g. ipify.org, ip6.me, etc.) that provide a service that allows you to look up the other party's external IP address in a similar way without separate authentication, thereby ensuring service stability guaranteed.
Also, this library explicitly uses direct TCP socket connections and SSL connections to use IPv4 or IPv6 communication.
Microsoft.Extensions.DependencyInjection (net6.0+)| Service | Protocol | Type |
|---|---|---|
CloudflareTraceService | HTTPS | HTTP |
IpifyService | HTTPS | HTTP |
SeeIPService | HTTPS | HTTP |
IP6MeService | HTTPS | HTTP |
CurlMyIPService | HTTPS | HTTP |
ICanHazIPService | HTTPS | HTTP |
IFConfigService | HTTPS | HTTP (supports rich info) |
GoogleStunService | UDP | STUN |
GoogleStun1Service ~ GoogleStun4Service | UDP | STUN |
DistributedGoogleStunService | UDP | STUN |
netstandard2.0, net6.0, net8.0ReflectAllAsync / GetConsensusAddress for consensus-based IP resolutionTimeSpan overloads)IRichAddressReflectionService and IPAddressInfo for detailed geo/network infoservices.AddReflectionIPAddress()) for net6.0+System.Text.Json to 9.0.1 (security fix)using ReflectionIPAddress;
var services = new PublicAddressReflectionServices()
.AddService<CloudflareTraceService>()
.AddService<IpifyService>()
.AddService<SeeIPService>()
.AddService<IP6MeService>()
.AddService<CurlMyIPService>()
.AddService<ICanHazIPService>()
.AddService<IFConfigService>()
.AddService<GoogleStunService>();
// Returns the IP address by checking for the fastest successful response among the specified services.
var ipv4Address = await services.ReflectIPv4Async();
var sslipDomain = ipv4Address.ToSSLIPDomain();
Console.WriteLine($"IPv4 Address: {ipv4Address}, SSLIP Domain: {sslipDomain}");
// Each service gets 5 seconds to respond
var ipv4Address = await services.ReflectIPv4Async(TimeSpan.FromSeconds(5));
// Query all services and get the most common result
var allResults = await services.ReflectAllIPv4Async(
perServiceTimeout: TimeSpan.FromSeconds(10));
var consensusIp = allResults.GetConsensusAddress();
Console.WriteLine($"Consensus IP: {consensusIp} (from {allResults.Count} services)");
// Get detailed information including country, city, ASN, etc.
var ifconfig = new IFConfigService();
var info = await ifconfig.ReflectDetailedAsync();
Console.WriteLine($"IP: {info.Address}");
Console.WriteLine($"Country: {info.Country} ({info.CountryISO})");
Console.WriteLine($"City: {info.City}");
Console.WriteLine($"ASN: {info.ASN} ({info.ASNOrganization})");
Console.WriteLine($"TimeZone: {info.TimeZone}");
// In Program.cs or Startup.cs
services.AddReflectionIPAddress(); // Registers all built-in services
// Or configure specific services
services.AddReflectionIPAddress(builder =>
{
builder.AddService<CloudflareTraceService>();
builder.AddService<GoogleStunService>();
});
// Then inject and use
public class MyService
{
private readonly PublicAddressReflectionServices _reflectionServices;
public MyService(PublicAddressReflectionServices reflectionServices)
=> _reflectionServices = reflectionServices;
public Task<IPAddress> GetMyIpAsync()
=> _reflectionServices.ReflectIPv4Async();
}
This library follows Apache-2.0 license. See LICENSE file for more information.