Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. String ip = 85.64.225.159;
  2. int caching1 = IP2Country.NO_CACHE; // Straight on file, Fastest startup, slowest queries
  3. int caching2 = IP2Country.MEMORY_MAPPED; // Memory mapped file, fast startup, fast queries.
  4. int caching3 = IP2Country.MEMORY_CACHE; // load file into memory, slowerst startup, fastest queries
  5. IP2Country ip2c = new IP2Country(caching1);
  6. Country c = ip2c.getCountry(ip);
  7. if (c == null)
  8. {
  9. System.out.println("UNKNOWN");
  10. }
  11. else
  12. {
  13. // will output IL ISR ISRAEL
  14. System.out.println(c.get2cStr() + " " + c.get3cStr() + " " + c.getName());
  15. }
  16.  
  17. * Begining of IP address range
  18. * Ending of IP address range
  19. * Two-character country code based on ISO 3166
  20. * Three-character country code based on ISO 3166
  21. * Country name based on ISO 3166
  22.  
  23. FIELD DATA TYPE FIELD DESCRIPTION
  24. IP_FROM NUMERICAL (DOUBLE) Beginning of IP address range.
  25. IP_TO NUMERICAL (DOUBLE) Ending of IP address range.
  26. COUNTRY_CODE2 CHAR(2) Two-character country code based on ISO 3166.
  27. COUNTRY_CODE3 CHAR(3) Three-character country code based on ISO 3166.
  28. COUNTRY_NAME VARCHAR(50) Country name based on ISO 3166
  29.  
  30. SELECT COUNTRY_NAME FROM <TableName> WHERE IP_FROM <= IP Number and IP_TO >= IP Number
  31.  
  32. IP Number = A x (256*256*256) + B x (256*256) + C x 256 + D
  33.  
  34. SELECT Country from GeoIP where IpFrom < $IP and $IP < $IpTo
  35.  
  36. select country from geoip where $ip <= ipTo limit 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement