- Timestamp:
- 2019-10-24T23:22:30+13:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/maori-lang-detection/src/org/greenstone/atea/Utility.java
r33603 r33604 54 54 * version I'm using: https://github.com/maxmind/geoip-api-java 55 55 * Newer version: https://maxmind.github.io/GeoIP2-java/ 56 * 57 * @return 2 letter countrycode in uppercase or an exception 56 58 */ 59 public static String getCountryCodeOfDomain(String domainWithProtocol, File geoLiteCityDatFile) 60 throws Exception 61 { 62 int startIndex = domainWithProtocol.indexOf("//"); // http:// or https:// prefix 63 startIndex = (startIndex == -1) ? 0 : (startIndex+2); // skip past the protocol's // portion 64 String domain = domainWithProtocol.substring(startIndex); 65 66 // pass in the GeoLiteCity.dat file to be able to do the location lookup for domain's IP 67 LookupService cl = new LookupService(geoLiteCityDatFile, LookupService.GEOIP_MEMORY_CACHE); 68 69 // get IP for domain 70 InetAddress inetAddress = InetAddress.getByName(domain); 71 String ipAddress = inetAddress.getHostAddress(); 72 73 // get location object for IP 74 Location location = cl.getLocation(ipAddress); 75 76 if(location == null) { 77 throw new Exception("@@@@ No location info in DB for: " + domain); 78 } else { 79 return location.countryCode; 80 } 81 82 } 83 57 84 public static boolean isDomainInCountry(String domainWithProtocol, 58 85 String countryCode, File geoLiteCityDatFile)
Note:
See TracChangeset
for help on using the changeset viewer.