private static int Lookup(LookupOptions opts) { var url = opts.RedisUrl ?? GetEnv("REDIS_URL", "localhost:6379"); var ip = opts.Ip ?? GetEnv("LOOKUP_IP", "1.1.2.245"); var conn = ConnectionMultiplexer.Connect($"{url}, allowadmin=true"); var geoIp = new GeoIp(() => conn.GetDatabase()); var lookup = geoIp.LookupAsync(ip).Result; Console.WriteLine($"Looked up country for {ip}: '{lookup.Name}'"); return(0); }
// ReSharper restore ClassNeverInstantiated.Local // ReSharper restore UnusedAutoPropertyAccessor.Local private static int Upload(UploadOptions opts) { var url = opts.RedisUrl ?? GetEnv("REDIS_URL", "localhost:6379"); var csvFile = opts.CsvFile ?? GetEnv("GEOIP_CSV", "GeoIPCountryWhois.csv"); var conn = ConnectionMultiplexer.Connect($"{url}, allowadmin=true"); var geoIp = new GeoIp(() => conn.GetDatabase()); using (var reader = new StreamReader(csvFile)) { Console.WriteLine($"Importing '{csvFile}..."); var count = geoIp.ImportGeoLiteLegacyAsync(reader).Result; Console.WriteLine($"Imported {count} GeoIP Records."); } return(0); }