Navigation Menu

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

Commit

Permalink
Added support for GeoIP Netspeed lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas J Mather committed Jan 19, 2006
1 parent 5747e00 commit 93bab71
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
@@ -1,3 +1,5 @@
1.5 January 19th, 2006
- Added support for GeoIP Netspeed lookups (Frank Mather)
- Replaced Yugoslavia with Serbia and Montenegro - Replaced Yugoslavia with Serbia and Montenegro


1.4 December 18th, 2004 1.4 December 18th, 2004
Expand Down
3 changes: 3 additions & 0 deletions DatabaseInfo.cs
Expand Up @@ -31,6 +31,9 @@ public class DatabaseInfo {
public static int CITY_EDITION_REV1 = 2; public static int CITY_EDITION_REV1 = 2;
public static int ORG_EDITION = 5; public static int ORG_EDITION = 5;
public static int ISP_EDITION = 4; 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"); //private static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");


Expand Down
38 changes: 35 additions & 3 deletions LookupService.cs
@@ -1,7 +1,7 @@
/** /**
* LookupService.cs * 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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public * modify it under the terms of the GNU General Public
Expand Down Expand Up @@ -52,6 +52,10 @@ public class LookupService{
private static int WORLD_OFFSET = 1353; private static int WORLD_OFFSET = 1353;
public static int GEOIP_STANDARD = 0; public static int GEOIP_STANDARD = 0;
public static int GEOIP_MEMORY_CACHE = 1; 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 = { private static String[] countryCode = {
"--","AP","EU","AD","AE","AF","AG","AI","AL","AM","AN","AO","AQ","AR", "--","AP","EU","AD","AE","AF","AG","AI","AL","AM","AN","AO","AQ","AR",
Expand Down Expand Up @@ -166,7 +170,8 @@ public class LookupService{
} else if (databaseType == DatabaseInfo.CITY_EDITION_REV0 || } else if (databaseType == DatabaseInfo.CITY_EDITION_REV0 ||
databaseType == DatabaseInfo.CITY_EDITION_REV1 || databaseType == DatabaseInfo.CITY_EDITION_REV1 ||
databaseType == DatabaseInfo.ORG_EDITION || databaseType == DatabaseInfo.ORG_EDITION ||
databaseType == DatabaseInfo.ISP_EDITION) databaseType == DatabaseInfo.ISP_EDITION ||
databaseType == DatabaseInfo.ASNUM_EDITION)
{ {
databaseSegments = new int[1]; databaseSegments = new int[1];
databaseSegments[0] = 0; databaseSegments[0] = 0;
Expand All @@ -190,7 +195,9 @@ public class LookupService{
//file.Seek(file.position-4,SeekOrigin.Begin); //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 = new int[1];
databaseSegments[0] = COUNTRY_BEGIN; databaseSegments[0] = COUNTRY_BEGIN;
recordLength = STANDARD_RECORD_LENGTH; recordLength = STANDARD_RECORD_LENGTH;
Expand Down Expand Up @@ -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(){ public DatabaseInfo getDatabaseInfo(){
if (databaseInfo != null) { if (databaseInfo != null) {
return databaseInfo; return databaseInfo;
Expand Down
18 changes: 18 additions & 0 deletions netspeedExample.cs
@@ -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.