Skip to content

Commit 96ecdfe

Browse files
committed
updated readme
1 parent e81026c commit 96ecdfe

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
1-
Java wrapper for the DB-IP dataset
1+
# Java DB-IP
2+
A simple to use Java library for the freely available DB-IP [IP address to city dataset](https://db-ip.com/db/download/city).
3+
**Requires Java 8**
4+
5+
#Before you begin
6+
The entire dataset is loaded into a [TreeMap](https://docs.oracle.com/javase/8/docs/api/allclasses-noframe.html) . Make sure that you have about **3 GB of Heap space** available to load it.
7+
8+
9+
#Instructions
10+
In order to get geographical information for an ip address, just pass the `dbip-city-latest.csv.gz` as a File object to `DbIpClient` as follows:
11+
12+
```java
13+
File gzip = new File(PATH_TO_dbip-city-latest.csv.gz);
14+
DbIpClient client = new DbIpClient(gzip);
15+
```
16+
17+
Once the data is loaded from the file into memory , any subsequent invocation of the above code **would not** re-load the data .
18+
19+
Next,just fetch the data for a ip ,like so :
20+
21+
```java
22+
DbIpClient client = new DbIpClient(gzip);
23+
GeoEntity geoEntity = client.lookup("31.45.127.255");
24+
String city = geoEntity.getCity();
25+
String country = geoEntity.getCountry();
26+
String province = geoEntity.getProvince();
27+
28+
System.out.println("city : " + city);
29+
System.out.println("province : " + province);
30+
System.out.println("country : " + country);
31+
```
32+
33+
This prints :
34+
```
35+
city : Oslo
36+
province : Oslo
37+
country : Norway
38+
```
39+
That's pretty much it.

src/main/java/in/ankushs/dbip/api/Test.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77

88
public class Test {
99
public static void main(String[] args) {
10+
File gzip = new File("/Users/Ankush/Downloads/dbip-city-latest.csv.gz");
11+
DbIpClient client = new DbIpClient(gzip);
12+
GeoEntity geoEntity = client.lookup("31.45.127.255");
13+
String city = geoEntity.getCity();
14+
String country = geoEntity.getCountry();
15+
String province = geoEntity.getProvince();
16+
17+
System.out.println("city : " + city);
18+
System.out.println("province : " + province);
19+
System.out.println("country : " + country);
1020

11-
12-
DbIpClient client = new DbIpClient(new File("/Users/Ankush/Downloads/dbip-city-latest.csv.gz"));
13-
System.out.println(client.lookup("31.45.127.255"));
14-
TreeMap<Integer,String> trees = new TreeMap<>();
15-
trees.put(1,"a");
16-
trees.put(1,"b");
17-
System.out.println(trees);
18-
}
21+
}
1922
}

0 commit comments

Comments
 (0)