<commit_before># go-whosonfirst-iplookup

Go package for doing IP address to Who's On First record lookups

## Usage

### Example

```
import (
	"github.com/whosonfirst/go-whosonfirst-iplookup"
	"github.com/whosonfirst/go-whosonfirst-log"
	"io"
	"net"
	"os"
)

mmdb := "GeoLite2-City.mmdb"
source := "concordances#wof-concordances-latest.csv"

// Or maybe something like this
// db := "whosonfirst-city-latest.mmdb"
// source := "whosonfirst"
// See the documentation on "sources" below for details

addr := "172.16.58.3"
ip := net.ParseIP(addr)

logger := log.NewWOFLogger("[wof-iplookup] ")
logger.AddLogger(writer, "warning")

// Note the lack of error-handling

lookup, _ := iplookup.NewIPLookup(mmdb, source, logger)
wofid, _ := lookup.Query(ip)
```
## Sources

### maxmind

When you specify source as `maxmind` you are telling the code "I have a standard MaxMind GeoLite2 database that has been _augmented_ with Who's On First IDs.

Please remember that these do _not_ include the default GeoLite2 that MaxMind distributes. You can either build a WOF-enabled GeoLite2 database using the [p5-Whosonfirst-MaxMind-Writer]() package or by downloading copies that Who's On First maintains. Links to the latter are included below.

### whosonfirst

When you specify source as `whosonfirst` you are telling the code "I have a non-standard MaxMind database that has been built using the [p5-Whosonfirst-MaxMind-Writer]() package or that you downloaded from Who's On First. Like the WOF-enabled GeoLite2 databases links are included below.

_These non-standard MaxMind databases are still considered experimental. While they will always contain a `whosonfirst_id` property it is still possible that other things may change._

### concordances

First the `concordances` source is actually `concordances#/some/path/to-a/concordances-file.csv`, most likely the [wof-concordances-latest.csv]() file included in the `whosonfirst-data` repository.

Okay, now that that's out of the way when you specify source as `concordances` you are telling the code "I have standard MaxMind GeoLite2 database that doesn't contain any Who's On First information _but_ I do have this handy CSV file that maps Geonames IDs to Who's On First IDs so please use that, okay?".

## Utilities

### wof-iplookup

```
$> ./bin/wof-iplookup -h
Usage of ./bin/wof-iplookup:
  -db string
      The path to your IP lookup database file
  -loglevel string
    	     (default "warning")
  -raw
	Dump the raw query response as JSON
  -source string
    	  The source of the IP lookups (default "maxmind")
```

Perform an IP lookup for a list of IP addresses passed on the command line. By default this emits a single Who's On First ID on a new line for each IP address passed in as an argument.

Here's an example using a `concordances` file as the input source and verbose logging, just so you can see what's going on under the hood:

```
$> ./bin/wof-iplookup -loglevel debug -db /usr/local/mapzen/mmdb/wof-mm-city.mmdb -source concordances#/usr/local/mapzen/whosonfirst-data/meta/wof-concordances-latest.csv 8.8.8.4
[wof-iplookup] 16:22:59.667597 [debug] create new IP lookup using /usr/local/mapzen/mmdb/wof-mm-city.mmdb (concordances#/usr/local/mapzen/whosonfirst-data/meta/wof-concordances-latest.csv)<commit_msg>links<commit_after># go-whosonfirst-iplookup

Go package for doing IP address to Who's On First record lookups

## Usage

### Example

```
import (
	"github.com/whosonfirst/go-whosonfirst-iplookup"
	"github.com/whosonfirst/go-whosonfirst-log"
	"io"
	"net"
	"os"
)

mmdb := "GeoLite2-City.mmdb"
source := "concordances#wof-concordances-latest.csv"

// Or maybe something like this
// db := "whosonfirst-city-latest.mmdb"
// source := "whosonfirst"
// See the documentation on "sources" below for details

addr := "172.16.58.3"
ip := net.ParseIP(addr)

logger := log.NewWOFLogger("[wof-iplookup] ")
logger.AddLogger(writer, "warning")

// Note the lack of error-handling

lookup, _ := iplookup.NewIPLookup(mmdb, source, logger)
wofid, _ := lookup.Query(ip)
```
## Sources

### maxmind

When you specify source as `maxmind` you are telling the code "I have a standard MaxMind GeoLite2 database that has been _augmented_ with Who's On First IDs.

Please remember that these do _not_ include the default GeoLite2 that MaxMind distributes. You can either build a WOF-enabled GeoLite2 database using the [p5-Whosonfirst-MaxMind-Writer](https://github.com/whosonfirst/p5-Whosonfirst-MaxMind-Writer) package or by downloading copies that Who's On First maintains. Links to the latter are included below.

### whosonfirst

When you specify source as `whosonfirst` you are telling the code "I have a non-standard MaxMind database that has been built using the [p5-Whosonfirst-MaxMind-Writer](https://github.com/whosonfirst/p5-Whosonfirst-MaxMind-Writer) package or that you downloaded from Who's On First. Like the WOF-enabled GeoLite2 databases links are included below.

_These non-standard MaxMind databases are still considered experimental. While they will always contain a `whosonfirst_id` property it is still possible that other things may change._

### concordances

First the `concordances` source is actually `concordances#/some/path/to-a/concordances-file.csv`, most likely the [wof-concordances-latest.csv](https://github.com/whosonfirst/whosonfirst-data/blob/master/meta/wof-concordances-latest.csv) file included in the `whosonfirst-data` repository.

Okay, now that that's out of the way when you specify source as `concordances` you are telling the code "I have standard MaxMind GeoLite2 database that doesn't contain any Who's On First information _but_ I do have this handy CSV file that maps Geonames IDs to Who's On First IDs so please use that, okay?".

## Utilities

### wof-iplookup

```
$> ./bin/wof-iplookup -h
Usage of ./bin/wof-iplookup:
  -db string
      The path to your IP lookup database file
  -loglevel string
    	     (default "warning")
  -raw
	Dump the raw query response as JSON
  -source string
    	  The source of the IP lookups (default "maxmind")
```

Perform an IP lookup for a list of IP addresses passed on the command line. By default this emits a single Who's On First ID on a new line for each IP address passed in as an argument.

Here's an example using a `concordances` file as the input source and verbose logging, just so you can see what's going on under the hood:

```
$> ./bin/wof-iplookup -loglevel debug -db /usr/local/mapzen/mmdb/wof-mm-city.mmdb -source concordances#/usr/local/mapzen/whosonfirst-data/meta/wof-concordances-latest.csv 8.8.8.4
[wof-iplookup] 16:22:59.667597 [debug] create new IP lookup using /usr/local/mapzen/mmdb/wof-mm-city.mmdb (concordances#/usr/local/mapzen/whosonfirst-data/meta/wof-concordances-latest.csv)
{'fraction_non_alphanumeric': 0.09701271813073055, 'fraction_numerical': 0.009760425909494233, 'mean_word_length': 4.3001567398119125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3559783', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2157, 'n_words': 785}