This project, AKA nimip, is a hybrid and asynchronous wrapper around ip-api, a free geolocation API which can be used to lookup a domain or IP address. The user can provide an IPv4 / IPv6 compliant address and nimip can query for it with speed, whilst being a very tiny package.
As a developer, I'm still learning the Nim programming language (pretty awesome!) and nimip is one of my hobby projects which I had a lot of fun programming on. It has definitely helped me get in-depth with the language itself and hopefully, it'll be helpful to those who need to constantly access information on IP addresses.
-
Nim (using nimble)
# Requires Nim v2.0 or greater.
$ nimble install nimip
-
macOS (using Homebrew)
# Tapping the formula.
$ brew tap hitblast/nimtap
# Install using the `brew install` command.
$ brew install nimip
You can manually download the packaged versions of nimip from the latest release in the Releases section. The build artifacts are also stored for you to download as well.
This project is written as a hybrid package. Meaning that it can be used as both a Nim library and a standalone CLI application inside your terminal. The choice is yours.
After installing the package (see this section), the binary for nimip should be in your PATH
variable depending on how you've installed it. This means, a new nimip
command will be added to your shell environment.
# Add binary to PATH.
$ export PATH="path/to/nimip/binary:$PATH"
Afterwards, simply run it using the following command snippets:
# The default help command.
$ nimip --help # -h also works
# Lookup an IP.
$ nimip 104.21.29.128
This project can also be used as a Nim library. Here's an example snippet for you to have a look at. For more information on the different procedure, try having a look at the official documentation.
# Sample imports.
import std/[
asyncdispatch,
strformat
]
import nimip/main
# Creating a new IP reference object.
let ip = IPRef(
address: "104.21.29.128",
locale: Locale.EN
)
# The main procedure.
proc main() {.async.} =
# Checks if the IP address can be queried.
try:
await ip.refreshData()
except IPResponseError:
echo "Could not query for IP address."
quit(1)
# If everything goes well, display the information.
echo fmt"IP Location: {ip.latitude}, {ip.longitude}"
# Running it.
waitFor main()
# Prepare a release build.
$ nimble build -d:ssl -d:release --accept
The various third-party libraries and dependancies used for developing this project are mentioned below:
-
Internal dependencies:
-
External dependencies (noted in the root .nimble file):
- OpenSSL for connection and making API calls.
This project is licensed under the MIT License.