private string GetCountryCode(string strIPAddress) { string result = "-"; IP2Location.IPResult oIPResult = new IP2Location.IPResult(); IP2Location.Component oIP2Location = new IP2Location.Component(); try { if (strIPAddress != "") { oIP2Location.IPDatabasePath = Server.MapPath("bin") + "/IPV6-COUNTRY-REGION-CITY.BIN"; // for both IPv4 & IPv6 //oIP2Location.IPDatabasePath = Server.MapPath("bin") + "/IP-COUNTRY-REGION-CITY.BIN"; // for just IPv4 // oIP2Location.IPDatabasePath = @"C:\Program Files\IP2Location\IP2LOCATION-LITE-DB1.IPV6.BIN"; // for both IPv4 & IPv6 //Set License Path oIP2Location.IPLicensePath = Server.MapPath("bin") + "/License.key"; oIPResult = oIP2Location.IPQuery(strIPAddress); if (oIPResult.Status.ToString() == "OK") { result = oIPResult.CountryShort; } } } catch (Exception ex) { } finally { oIPResult = null; oIP2Location = null; } return(result); }
private void setMetaFields(IP2Location.Component ip2l) { if (ip2l != null) { var qr = ip2l.IPQuery(ToString()); City = qr.City; Country = qr.CountryLong; Region = qr.Region; Latitude = qr.Latitude; Longitude = qr.Longitude; ZipCode = qr.ZipCode; TimeZone = qr.TimeZone; } }
public List <String> getGeoInfo(String ip2Geo) { IP2Location.IPResult oIPResult = new IP2Location.IPResult(); IP2Location.Component oIP2Location = new IP2Location.Component(); List <String> ipInfos = new List <string>(); try { oIP2Location.IPDatabasePath = Environment.CurrentDirectory + @"\\Location DB\\IP2LOCATION-LITE-DB11.BIN"; oIPResult = oIP2Location.IPQuery(ip2Geo); if (oIPResult.Status.ToString().Equals("OK")) { ipInfos.Add(oIPResult.CountryLong); ipInfos.Add(oIPResult.City); ipInfos.Add(oIPResult.Region); ipInfos.Add(oIPResult.ZipCode); ipInfos.Add(oIPResult.TimeZone); return(ipInfos); } else { List <String> errorLists = new List <string>(); errorLists.Add(oIPResult.Status.ToString()); errorLists.Add(oIPResult.Status.ToString()); errorLists.Add(oIPResult.Status.ToString()); errorLists.Add(oIPResult.Status.ToString()); errorLists.Add(oIPResult.Status.ToString()); return(errorLists); } } catch { List <String> errorListse = new List <string>(); errorListse.Add("No Data in DB"); errorListse.Add("No Data in DB"); errorListse.Add("No Data in DB"); errorListse.Add("No Data in DB"); errorListse.Add("No Data in DB"); return(errorListse); } }
public static GeoLocation GetGeoLocation(string strIPAddress) { IP2Location.IPResult oIPResult = new IP2Location.IPResult(); IP2Location.Component oIP2Location = new IP2Location.Component(); try { if (!string.IsNullOrEmpty(strIPAddress)) { oIP2Location.IPDatabasePath = GetGeoDBLocation(); oIPResult = oIP2Location.IPQuery(strIPAddress); switch (oIPResult.Status.ToString()) { case "OK": return(new GeoLocation() { City = oIPResult.City, CountryShort = oIPResult.CountryShort, CountryLong = oIPResult.CountryLong, ZipCode = oIPResult.ZipCode, DomainName = oIPResult.DomainName, InternetServiceProvider = oIPResult.InternetServiceProvider, Latitude = oIPResult.Latitude.ToString(), Longitude = oIPResult.Longitude.ToString() }); } } } catch (Exception ex) { return(null); } finally { oIPResult = null; oIP2Location = null; } return(null); }
static public string GetCountryCode(string strIPAddress) { if (DB_PATH == null) { string path = HttpContext.Current.Server.MapPath("~/App_Data"); DB_PATH = path + "/IP-COUNTRY.BIN"; LIC_PATH = path + "/License.key"; } IP2Location.IPResult oIPResult = new IP2Location.IPResult(); IP2Location.Component oIP2Location = new IP2Location.Component(); try { //Set Database Paths oIP2Location.IPDatabasePath = DB_PATH; oIP2Location.IPLicensePath = LIC_PATH; oIPResult = oIP2Location.IPQuery(strIPAddress); switch (oIPResult.Status.ToString()) { case "OK": return(oIPResult.CountryShort); default: return(null); } } catch (Exception ex) { throw new ApiExitException(ex.Message); } finally { oIPResult = null; oIP2Location = null; } }
private static void WorkLoop() { var repo = new ProxyRepository(new ProxyDbContext()); foreach (var line in pendingLines.GetConsumingEnumerable()) { var parts = line.Split(':'); var ip = parts[0]; var port = ushort.Parse(parts[1]); var result = IpQuery.IPQuery(ip); var proxyResult = ProxyQuery.GetAll(ip); var lastSeen = DateTime.MinValue; if (int.TryParse(proxyResult.Last_Seen, out var days)) { lastSeen = DateTime.UtcNow - TimeSpan.FromDays(days); } switch (proxyResult.Usage_Type) { case "COM": proxyResult.Usage_Type = "Commercial"; break; case "ORG": proxyResult.Usage_Type = "Organization"; break; case "GOV": proxyResult.Usage_Type = "Government"; break; case "MIL": proxyResult.Usage_Type = "Military"; break; case "EDU": proxyResult.Usage_Type = "University/College/School"; break; case "LIB": proxyResult.Usage_Type = "Library"; break; case "CDN": proxyResult.Usage_Type = "Content Delivery Network"; break; case "ISP": proxyResult.Usage_Type = "Fixed Line ISP"; break; case "MOB": proxyResult.Usage_Type = "Mobile ISP"; break; case "ISP/MOB": proxyResult.Usage_Type = "Fixed/Mobile ISP"; break; case "DCH": proxyResult.Usage_Type = "Data Center/Web Hosting/Transit"; break; case "SES": proxyResult.Usage_Type = "Search Engine Spider"; break; case "-": proxyResult.Usage_Type = ""; break; } var proxy = new Proxy { ID = Helpers.IpToInt(ip), IP = ip, Port = port, City = result.City, Country = result.CountryLong, Region = result.Region, Longitude = result.Longitude, Latitude = result.Latitude, AS = proxyResult.AS, ASN = proxyResult.ASN, Domain = proxyResult.Domain, ISP = proxyResult.ISP, LastSeen = lastSeen, Threat = proxyResult.Threat, ProxyType = proxyResult.Usage_Type }; foreach (var m in proxy.GetType().GetProperties()) { if (m.PropertyType != typeof(String)) { continue; } var val = (string)m.GetValue(proxy); if (val != "-") { continue; } m.SetValue(proxy, string.Empty); val = (string)m.GetValue(proxy); } repo.AddOrUpdateProxy(proxy); _cache.TryRemove(ip, out _); Interlocked.Increment(ref processedLines); Console.WriteLine($"Processed: {processedLines}, Pending:{pendingLines.Count}"); } }