Skip to content

Commit

Permalink
Merge branch 'release/0.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
axllent committed Mar 2, 2019
2 parents 8994f61 + 87d7873 commit 81b4758
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/pkg/
/src/
geoiplookup
goiplookup
goiplookup*.bz2
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# GoIpLookup - geoiplookup for GeoLite2-Country written in Go

GoIpLookup is a geoiplookup replacement for the [free GeoLite2-Country](https://dev.maxmind.com/geoip/geoip2/geolite2/),
written in [Go](https://golang.org/).

It currently only supports the free GeoLite2-Country database, and there is no planned support for the other types.


## Features

- Drop-in replacement for the now defunt geoiplookup utility
- Works with the current Maxmind database format (mmdd)
- IPv4, IPv6 and fully qualified domain name (FQDN) support
- Built-in database update support
- Options to return just the country iso (`NZ`) or country name (`New Zealand`), rather than the full `GeoIP Country Edition: NZ, New Zealand`


## Installing

Linux amd64 binaries are supplied with releases.

```
bunzip goiplookup_linux_amd64.bz2
chmod 755 goiplookup_linux_amd64
sudo mv goiplookup_linux_amd64 /usr/local/bin/goiplookup
```

If you with to replace an existing defunct implementation of geoiplookup, then simply name the file `geoiplookup`.


## Compiling from source

You must have golang installed. There is one external library required ([oschwald/geoip2-golang](github.com/oschwald/geoip2-golang)) which is downloaded automatically when you run `make`:

```
git clone git@github.com:axllent/goiplookup.git
cd goiplookup
make
```

## Basic usage
```
Usage: goiplookup [-i] [-c] [-d <database directory>] <ipaddress|hostname|db-update>
Options:
-V show version number
-c return country name
-d string
database directory or file (default "/usr/share/GeoIP")
-h show help
-i return country iso code
-v verbose/debug output
Examples:
./goiplookup 8.8.8.8 Return the country ISO code and name
./goiplookup -d ~/GeoIP 8.8.8.8 Use a different database directory
./goiplookup -i 8.8.8.8 Return just the country ISO code
./goiplookup -c 8.8.8.8 Return just the country name
./goiplookup db-update Update the GeoLite2-Country database (do not run more than once a month)
```
8 changes: 4 additions & 4 deletions goiplookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func main() {

lookup := flag.Args()[0]

if lookup == "update" {
if lookup == "db-update" {
UpdateGeoLite2Country()
} else {
Lookup(lookup)
Expand Down Expand Up @@ -255,16 +255,16 @@ func ExtractDatabase(dst string, targz string) error {

// Print the help function
var Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [-i] [-c] [-d <database directory>] <ipaddress|hostname|update>\n", os.Args[0])
fmt.Fprintf(os.Stderr, "Usage: %s [-i] [-c] [-d <database directory>] <ipaddress|hostname|db-update>\n", os.Args[0])
fmt.Println("\nGoiplookup uses the GeoLite2-Country database to find the Country that an IP address or hostname originates from.")
fmt.Println("\nOptions:")
flag.PrintDefaults()
fmt.Println("\nExamples:")
fmt.Fprintf(os.Stderr, "%s 8.8.8.8\t\t\tReturn the country ISO code and name\n", os.Args[0])
fmt.Fprintf(os.Stderr, "%s -d ~/GeoIP 8.8.8.8\t\tUse a different database directory\n", os.Args[0])
fmt.Fprintf(os.Stderr, "%s -i 8.8.8.8\t\t\tReturn just the country ISO code\n", os.Args[0])
fmt.Fprintf(os.Stderr, "%s -n 8.8.8.8\t\t\tReturn just the country name\n", os.Args[0])
fmt.Fprintf(os.Stderr, "%s update\t\t\tUpdate the GeoLite2-Country database (do not run more than once a month)\n", os.Args[0])
fmt.Fprintf(os.Stderr, "%s -c 8.8.8.8\t\t\tReturn just the country name\n", os.Args[0])
fmt.Fprintf(os.Stderr, "%s db-update\t\t\tUpdate the GeoLite2-Country database (do not run more than once a month)\n", os.Args[0])
}

// Display debug information with `-v`
Expand Down

0 comments on commit 81b4758

Please sign in to comment.