Repository

ipapi-v

A V module to query IP addresses using the ipquery.io API.

Overview

ipapi-v is a lightweight V module that fetches information about IP addresses using the api.ipquery.io API. You can query a specific IP address or fetch the public IP address of the current machine.

Features

  • Query detailed information for a specific IP address.
  • Fetch geographical and ISP data.
  • Check if an IP address is associated with VPNs, proxies, or data centers.
  • Get the public IP address of your own machine.

Installation

To install the package, run:

v install ipapi

Importing the Package

import ipapi

Usage Examples

Query a Specific IP Address

module main

import ipapi

fn main() {
    ip_info := ipapi.query_ip('8.8.8.8') or {
        println('failed to query IP: ${err}')
        return
    }

    println('IP: ${ip_info.ip}')
    println('Country: ${ip_info.location.country}')
    println('ISP: ${ip_info.isp.isp}')
}

Fetch Your Own Public IP Address

module main

import ipapi

fn main() {
    ip := ipapi.query_own_ip() or {
        println('failed to fetch own IP: ${err}')
        return
    }

    println('Your IP: ${ip}')
}

Struct Definitions

The module exposes these data structures:

  • ISPInfo
  • LocationInfo
  • RiskInfo
  • IPInfo

Testing

The package includes unit tests to ensure functionality. To run the tests and see the logged output, use:

v -stats test .

The current tests look like this:

module ipapi

fn test_query_ip() {
    ip_info := query_ip('8.8.8.8') or {
        panic('Failed to query IP: ${err}')
    }
    eprintln('query_ip: ip=${ip_info.ip} country=${ip_info.location.country} isp=${ip_info.isp.isp}')
    assert ip_info.ip == '8.8.8.8'
}

fn test_query_own_ip() {
    ip := query_own_ip() or {
        panic('Failed to fetch own IP: ${err}')
    }
    eprintln('query_own_ip: ip=${ip}')
    assert ip != ''
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

  • This package uses the api.ipquery.io API for IP information.
  • Inspired by various IP geolocation services.

Links

About

ipapi-v is a lightweight V module for querying IP details, including ISP, location, risk data, and the current machine’s public IP.

0
0
5 hours ago

Author

xn0px90