Permalink
Browse files

Throws an exception if the dbfile is not found.

- LookupService throws an exception if the database file is not found. (
Guenter Knauf )
- Cleanup the example files ( Guenter Knauf )
- Add new example infoExample.cs ( Guenter Knauf )
  • Loading branch information...
1 parent c6c5d51 commit 04e95c578c1d011de7c4fd497cb9f809a76ad600 @borisz borisz committed with oschwald Oct 22, 2012
View
@@ -1,5 +1,8 @@
1.19 ???
- Add NetSpeedCell example ( Boris Zentner )
+ - LookupService throws an exception if the database file is not found. ( Guenter Knauf )
+ - Cleanup the example files ( Guenter Knauf )
+ - Add new example infoExample.cs ( Guenter Knauf )
1.18 Feb 20th, 2013
- Add South Sudan ( Boris Zentner )
- Update FIPS codes ( Boris Zentner )
View
@@ -118,15 +118,11 @@ public class LookupService{
"Saint Barthelemy","Saint Martin", "Bonaire, Saint Eustatius and Saba", "South Sudan", "Other"};
public LookupService(String databaseFile, int options){
- try {
- lock ( ioLock ) {
- this.file = new FileStream(databaseFile, FileMode.Open, FileAccess.Read);
- }
- dboptions = options;
- init();
- } catch(System.SystemException) {
- Console.Write("cannot open file " + databaseFile + "\n");
+ lock ( ioLock ) {
+ this.file = new FileStream(databaseFile, FileMode.Open, FileAccess.Read);
}
+ dboptions = options;
+ init();
}
public LookupService(String databaseFile):this(databaseFile, GEOIP_STANDARD){
@@ -3,8 +3,10 @@
using System.IO;
class Appa0{
public static void Main(String[] args){
+ string GeoipDbPath = "/usr/local/share/GeoIP/";
+ string GeoipDb = GeoipDbPath + "GeoIPASNum.dat";
//open the database
- LookupService ls = new LookupService("/usr/local/share/GeoIP/GeoIPASNum.dat", LookupService.GEOIP_STANDARD);
+ LookupService ls = new LookupService(GeoipDb, LookupService.GEOIP_STANDARD);
//get org of the ip address
String orgorisp = ls.getOrg("24.24.24.24");
Console.Write("asn: " + orgorisp + "\n");
@@ -3,8 +3,10 @@
using System.IO;
class Appa0{
public static void Main(String[] args){
+ string GeoipDbPath = "/usr/local/share/GeoIP/";
+ string GeoipDb = GeoipDbPath + "GeoIPASNumv6.dat";
//open the database
- LookupService ls = new LookupService("/usr/local/share/GeoIP/GeoIPASNumv6.dat", LookupService.GEOIP_STANDARD);
+ LookupService ls = new LookupService(GeoipDb, LookupService.GEOIP_STANDARD);
//get org of the ip address
String orgorisp = ls.getOrgV6("2001:4860:0:1001::68");
Console.Write("asn: " + orgorisp + "\n");
@@ -3,9 +3,11 @@
using System.IO;
class Appa0{
public static void Main(String[] args){
+ string GeoipDbPath = "/usr/local/share/GeoIP/";
+ string GeoipDb = GeoipDbPath + "GeoIPCity.dat";
//open the database
try {
- LookupService ls = new LookupService("/usr/local/share/GeoIP/GeoIPCity.dat", LookupService.GEOIP_STANDARD);
+ LookupService ls = new LookupService(GeoipDb, LookupService.GEOIP_STANDARD);
//get city location of the ip address
if (args.Length > 0) {
Location l = ls.getLocation(args[0]);
@@ -3,9 +3,11 @@
using System.IO;
class Appa0{
public static void Main(String[] args){
+ string GeoipDbPath = "/usr/local/share/GeoIP/";
+ string GeoipDb = GeoipDbPath + "GeoIPCity.dat";
//open the database
try {
- LookupService ls = new LookupService("/usr/local/share/GeoIP/GeoLiteCityV6.dat", LookupService.GEOIP_STANDARD);
+ LookupService ls = new LookupService(GeoipDb, LookupService.GEOIP_STANDARD);
//get city location of the ip address
if (args.Length > 0) {
Location l = ls.getLocationV6(args[0]);
@@ -8,8 +8,10 @@
using System.IO;
class Appa0{
public static void Main(String[] args){
+ string GeoipDbPath = "/usr/local/share/GeoIP/";
+ string GeoipDb = GeoipDbPath + "GeoIP.dat";
//open the database
- LookupService ls = new LookupService("/usr/local/share/GeoIP/GeoIP.dat", LookupService.GEOIP_MEMORY_CACHE);
+ LookupService ls = new LookupService(GeoipDb, LookupService.GEOIP_MEMORY_CACHE);
//get country of the ip address
Country c = ls.getCountry("24.24.24.24");
Console.Write(" code: " + c.getCode()+"\n");
@@ -8,8 +8,10 @@
using System.IO;
class Appa0{
public static void Main(String[] args){
+ string GeoipDbPath = "/usr/local/share/GeoIP/";
+ string GeoipDb = GeoipDbPath + "GeoIP.dat";
//open the database
- LookupService ls = new LookupService("/usr/local/share/GeoIP/GeoIPv6.dat", LookupService.GEOIP_MEMORY_CACHE);
+ LookupService ls = new LookupService(GeoipDb, LookupService.GEOIP_MEMORY_CACHE);
//get country of the ip address
Country c = ls.getCountryV6("2001:4860:0:1001::68");
Console.Write(" code: " + c.getCode()+"\n");
@@ -2,7 +2,10 @@
using System.IO;
class Appa0{
public static void Main(String[] args){
- LookupService ls = new LookupService("/usr/local/share/GeoIP/GeoIPNetSpeed.dat", LookupService.GEOIP_STANDARD);
+ string GeoipDbPath = "/usr/local/share/GeoIP/";
+ string GeoipDb = GeoipDbPath + "GeoIPNetSpeed.dat";
+ //open the database
+ LookupService ls = new LookupService(GeoipDb, LookupService.GEOIP_STANDARD);
int id = ls.getID(args[0]);
int speed = id;
if (speed == LookupService.GEOIP_UNKNOWN_SPEED){
@@ -3,8 +3,10 @@
using System.IO;
class Appa0{
public static void Main(String[] args){
+ string GeoipDbPath = "/usr/local/share/GeoIP/";
+ string GeoipDb = GeoipDbPath + "GeoIPOrg.dat";
//open the database
- LookupService ls = new LookupService("/usr/local/share/GeoIP/GeoIPOrg.dat", LookupService.GEOIP_STANDARD);
+ LookupService ls = new LookupService(GeoipDb, LookupService.GEOIP_STANDARD);
//get org of the ip address
String orgorisp = ls.getOrg("24.24.24.24");
Console.Write(" org: " + orgorisp + "\n");
@@ -3,8 +3,10 @@
using System.IO;
class Appa0{
public static void Main(String[] args){
+ const string GeoipDbPath = "/usr/local/share/GeoIP/";
+ const string GeoipDb = GeoipDbPath + "GeoIPRegion.dat";
//open the database
- LookupService ls = new LookupService("/usr/local/share/GeoIP/GeoIPRegion.dat", LookupService.GEOIP_STANDARD);
+ LookupService ls = new LookupService(GeoipDb, LookupService.GEOIP_STANDARD);
//get region of the ip address
Region c = ls.getRegion("24.24.24.24");
Console.Write(" code: " + c.getcountryCode()+"\n");
View
@@ -0,0 +1,19 @@
+//an example of how to lookup the database info
+using System;
+using System.IO;
+class Appa0{
+ public static void Main(String[] args){
+ string GeoipDbPath = "/usr/local/share/GeoIP/";
+ string GeoipDb = GeoipDbPath + "GeoIPCity.dat";
+ if (args.Length > 0) {
+ GeoipDb = args[0];
+ }
+ //open the database
+ LookupService ls = new LookupService(GeoipDb, LookupService.GEOIP_STANDARD);
+ //get the database info
+ DatabaseInfo dbinfo = ls.getDatabaseInfo();
+ Console.Write(" dbinfo string: " + dbinfo.toString() + "\n");
+ Console.Write(" dbinfo type: " + dbinfo.getType() + "\n");
+ Console.Write(" dbinfo date: " + dbinfo.getDate() + "\n");
+ }
+}

0 comments on commit 04e95c5

Please sign in to comment.