Exemple #1
0
 public static string GetCountryCode(string ip, MaxmindSource mms = MaxmindSource.LocalDb, bool throwOnError = false, bool doNotWarnOnNotInDb = false)
 {
     try {
         using (WebServiceClient wsc = new MaxMind.GeoIP2.WebServiceClient(MAXMIND_WS_USER_ID, MAXMIND_WS_KEY)) {
             var ir = wsc.Insights(ip);
             LogIt.D(ir.Country.IsoCode + "|" + ir.City.Name);
             return(ir.Country.IsoCode);
         }
     } catch (Exception ex) {
         if (doNotWarnOnNotInDb && ex.Message.Contains("is not in the database"))
         {
             //LogIt.W(ip + "|" + ex.Message);
         }
         else
         {
             LogIt.W(ip + "|" + ex.Message);
         }
         if (throwOnError)
         {
             throw ex;
         }
         else
         {
             return(null);
         }
     }
 }
Exemple #2
0
 public static InsightsResponse GetOmniResponse(string ip)
 {
     try {
         using (WebServiceClient wsc = new MaxMind.GeoIP2.WebServiceClient(MAXMIND_WS_USER_ID, MAXMIND_WS_KEY)) {
             var ir = wsc.Insights(ip);
             LogIt.D(ir.Country.IsoCode + "|" + ir.City.Name);
             return(ir);
         }
     } catch (Exception ex) {
         LogIt.E(ex);
         LogIt.W(ip);
         throw ex;
     }
 }
Exemple #3
0
 public static string GetIsp(string ip, bool throwOnError = false)
 {
     try {
         using (WebServiceClient wsc = new MaxMind.GeoIP2.WebServiceClient(MAXMIND_WS_USER_ID, MAXMIND_WS_KEY)) {
             var ir = wsc.Insights(ip);
             LogIt.D(ir.Country.IsoCode + "|" + ir.City.Name);
             return(ir.Traits.Isp);
         }
     } catch (Exception ex) {
         LogIt.W(ip + "|" + ex.Message);
         if (throwOnError)
         {
             throw ex;
         }
         else
         {
             return(null);
         }
     }
 }