How to get current IP form ipify.org ?

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)
}
C:\golang\example>go fmt myip.go
myip.go

C:\golang\example>go run myip.go
Getting IP address from ipify
My IP is:49.34.146.212

C:\golang\example>

Thanks for reading. Please leave your valuable feedback and comments.

* Required Fields

No questions yet. Be the first to ask the question!