Permalink
Browse files

Added support for GeoIP Netspeed lookups

  • Loading branch information...
1 parent 5747e00 commit 93bab71bd01c2b8da6235925b5b016acc99c98bc Thomas J Mather committed Jan 19, 2006
Showing with 58 additions and 3 deletions.
  1. +2 −0 ChangeLog
  2. +3 −0 DatabaseInfo.cs
  3. +35 −3 LookupService.cs
  4. +18 −0 netspeedExample.cs
View
@@ -1,3 +1,5 @@
+1.5 January 19th, 2006
+ - Added support for GeoIP Netspeed lookups (Frank Mather)
- Replaced Yugoslavia with Serbia and Montenegro
1.4 December 18th, 2004
View
@@ -31,6 +31,9 @@ public class DatabaseInfo {
public static int CITY_EDITION_REV1 = 2;
public static int ORG_EDITION = 5;
public static int ISP_EDITION = 4;
+ public static int PROXY_EDITION = 8;
+ public static int ASNUM_EDITION = 9;
+ public static int NETSPEED_EDITION = 10;
//private static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
View
@@ -1,7 +1,7 @@
/**
* LookupService.cs
*
- * Copyright (C) 2004 MaxMind LLC. All Rights Reserved.
+ * Copyright (C) 2006 MaxMind LLC. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -52,6 +52,10 @@ public class LookupService{
private static int WORLD_OFFSET = 1353;
public static int GEOIP_STANDARD = 0;
public static int GEOIP_MEMORY_CACHE = 1;
+ public static int GEOIP_UNKNOWN_SPEED = 0;
+ public static int GEOIP_DIALUP_SPEED = 1;
+ public static int GEOIP_CABLEDSL_SPEED = 2;
+ public static int GEOIP_CORPORATE_SPEED = 3;
private static String[] countryCode = {
"--","AP","EU","AD","AE","AF","AG","AI","AL","AM","AN","AO","AQ","AR",
@@ -166,7 +170,8 @@ public class LookupService{
} else if (databaseType == DatabaseInfo.CITY_EDITION_REV0 ||
databaseType == DatabaseInfo.CITY_EDITION_REV1 ||
databaseType == DatabaseInfo.ORG_EDITION ||
- databaseType == DatabaseInfo.ISP_EDITION)
+ databaseType == DatabaseInfo.ISP_EDITION ||
+ databaseType == DatabaseInfo.ASNUM_EDITION)
{
databaseSegments = new int[1];
databaseSegments[0] = 0;
@@ -190,7 +195,9 @@ public class LookupService{
//file.Seek(file.position-4,SeekOrigin.Begin);
}
}
- if (databaseType == DatabaseInfo.COUNTRY_EDITION) {
+ if ((databaseType == DatabaseInfo.COUNTRY_EDITION) |
+ (databaseType == DatabaseInfo.PROXY_EDITION) |
+ (databaseType == DatabaseInfo.NETSPEED_EDITION)) {
databaseSegments = new int[1];
databaseSegments[0] = COUNTRY_BEGIN;
recordLength = STANDARD_RECORD_LENGTH;
@@ -240,6 +247,31 @@ public class LookupService{
}
}
+
+ public int getID(String ipAddress){
+ IPAddress addr;
+ try {
+ addr = IPAddress.Parse(ipAddress);
+ }
+ catch (Exception e) {
+ Console.Write(e.Message);
+ return 0;
+ }
+ return getID(swapbytes(addr.Address));
+ }
+
+ public int getID(IPAddress ipAddress) {
+
+ return getID(swapbytes(ipAddress.Address));
+ }
+
+ public int getID(long ipAddress){
+ if (file == null) {
+ throw new Exception("Database has been closed.");
+ }
+ int ret = SeekCountry(ipAddress) - databaseSegments[0];
+ return ret;
+ }
public DatabaseInfo getDatabaseInfo(){
if (databaseInfo != null) {
return databaseInfo;
View
@@ -0,0 +1,18 @@
+using System;
+using System.IO;
+class Appa0{
+ public static void Main(String[] args){
+ LookupService ls = new LookupService("/usr/local/share/GeoIP/GeoIPNetSpeed.dat", LookupService.GEOIP_STANDARD);
+ int id = ls.getID(args[0]);
+ int speed = id;
+ if (speed == LookupService.GEOIP_UNKNOWN_SPEED){
+ Console.Write("Unknown \n");
+ } else if (speed == LookupService.GEOIP_DIALUP_SPEED){
+ Console.Write("Dialup \n");
+ } else if (speed == LookupService.GEOIP_CABLEDSL_SPEED){
+ Console.Write("Cable/DSL \n");
+ } else if (speed == LookupService.GEOIP_CORPORATE_SPEED){
+ Console.Write("Corporate \n");
+ }
+ }
+}

0 comments on commit 93bab71

Please sign in to comment.