maxmind/GeoIP2-dotnet

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

sarus opened this issue · 2 comments

sarus commented

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?

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

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
}