maxmind / GeoIP2-dotnet

MaxMind GeoIP2 .NET API
https://www.nuget.org/packages/MaxMind.GeoIP2
Apache License 2.0
350 stars 78 forks source link

Expose Routing Prefix as Provided by MaxMind-DB-Reader-dotnet #56

Closed sarus closed 8 years ago

sarus commented 8 years ago

I wanted to provide a pull request to add the RoutingPrefix provided by MaxMind-DB-Reader-dotnet in version 2.0.0-beta3 to this library.

I was thinking it could be added as an additional overloaded version of TryIsp

 public bool TryIsp(IPAddress ipAddress, out IspResponse response, out int routingPrefix)

Would that work for y ou? Would you have a different preference for how to accomplish this?

oschwald commented 8 years ago

So I am a bit concerned about the combinatorial explosion of methods in this module. This use case seems pretty advanced. What is the disadvantage of just using MaxMind.Db directly along with the model class from this package? For example:

var reader = new Reader("GeoIP2-City.mmdb")
var response = reader.Find<IspResponse>(ipAddress, new InjectableValues(), out routingPrefix);
sarus commented 8 years ago

Good point. I think you're right about just accessing the Reader directly. In case anyone stumbles across this in the future here is what I needed to do:

var reader = new Reader("GeoIP2-City.mmdb", MaxMind.Db.FileAccessMode.Memory)
string ip = "8.8.8.8";
int routingPrefix = 0;
IPAddress ipAddress = IPAddress.Parse(ip);
var injectables = new MaxMind.Db.InjectableValues();
injectables.AddValue("ip_address", ip);
var cityResponse = reader.Find<MaxMind.GeoIP2.Responses.CityResponse>(ipAddress, out routingPrefix, injectables);
if(cityResponse != null){
     //lookup your values
}