Skip to content
This repository has been archived by the owner on Jul 4, 2019. It is now read-only.

Commit

Permalink
Throws an exception if the dbfile is not found.
Browse files Browse the repository at this point in the history
- 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
borisz authored and oschwald committed Sep 3, 2013
1 parent c6c5d51 commit 04e95c5
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 17 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
@@ -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 )
Expand Down
12 changes: 4 additions & 8 deletions LookupService.cs
Expand Up @@ -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){
Expand Down
4 changes: 3 additions & 1 deletion examples/asnExample.cs
Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion examples/asnV6Example.cs
Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion examples/cityExample.cs
Expand Up @@ -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]);
Expand Down
4 changes: 3 additions & 1 deletion examples/cityV6Example.cs
Expand Up @@ -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]);
Expand Down
4 changes: 3 additions & 1 deletion examples/countryExample.cs
Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion examples/countryV6Example.cs
Expand Up @@ -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");
Expand Down
5 changes: 4 additions & 1 deletion examples/netspeedExample.cs
Expand Up @@ -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){
Expand Down
4 changes: 3 additions & 1 deletion examples/orgExample.cs
Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion examples/regionExample.cs
Expand Up @@ -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");
Expand Down
19 changes: 19 additions & 0 deletions infoExample.cs
@@ -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.