How to get current IP form ipify.org ?


Example

package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {
	url := "https://api.ipify.org?format=text"
	fmt.Printf("Getting IP address from  ipify\n")
	resp, err := http.Get(url)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	ip, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Printf("My IP is:%s\n", ip)
}

Output

Getting IP address from  ipify
My IP is:49.34.146.212
Most Helpful This Week