Skip to content

A lightweight Go package for retrieving your machine's public IPv4/IPv6 and performing IP geolocation lookups using ipify and ipquery.io.

License

Notifications You must be signed in to change notification settings

ali-hasehmi/ipapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ipapi

ipapi is a simple, dependency free and lightweight Go package to fetch public IP address information (IPv4 and IPv6) of the current machine or any arbitrary IP address using third-party APIs

Features

  • 🔍 Get your machine's public IPv4 and IPv6 addresses separately.
  • 🌐 Lookup detailed geolocation and network info for any IP address.
  • ⚡ Uses two fast APIs: ipify.org for IP fetching, and ipquery.io for metadata.
  • 📦 Simple to use, easy to integrate.

Installation

go get github.com/ali-hasehmi/ipapi

Usage Examples

find my IPs

package main

import (
    "github.com/ali-hasehmi/ipapi"
    "log"
)

func main(){
    ipv4, err := ipapi.QueryOwnIPv4()
    if err != nil {
        log.Fatalln("error finding ipv4:", err)
    }
    ipv6, err := ipapi.QueryOwnIPv6()
    if err != nil {
        log.Fatalln("error finding ipv4:", err)
    }
    if ipv4 == "" {
        ipv4 = "none"
    }
    if ipv6 == ""{
        ipv6= "none"
    }
    log.Printf("your ipv4: %v\n",ipv4)
    log.Printf("your ipv6: %v\n",ipv6)
}

Find Everything About my machine IPs

package main

import (
	"encoding/json"
	"log"

	"github.com/ali-hasehmi/ipapi"
)

func main() {
	info, err := ipapi.QueryOwnIPInfo()
	if err != nil {
		log.Fatal(err)
	}
	b, err := json.MarshalIndent(info, "", "\t")
	if err != nil {
		log.Fatalln(info)
	}
	log.Println(string(b))
}

Find Everything About any IP

package main

import (
	"encoding/json"
	"log"

	"github.com/ali-hasehmi/ipapi"
)

func main() {
	info, err := ipapi.QueryIPInfo("1.1.1.1")
	if err != nil {
		log.Fatalln(err)
	}
	b, err := json.MarshalIndent(info, "", "\t")
	if err != nil {
		log.Fatalln(info)
	}
	log.Println(string(b))
}

Acknoledgments

About

A lightweight Go package for retrieving your machine's public IPv4/IPv6 and performing IP geolocation lookups using ipify and ipquery.io.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages