Skip to content

Commit

Permalink
Merge pull request #11 from NetSepio/rishikesh-ipinfo
Browse files Browse the repository at this point in the history
fix ipinfo
  • Loading branch information
Rushikeshnimkar authored Jun 6, 2024
2 parents f67a993 + b0afe6a commit f85ea1b
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions core/ipinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package core
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
)

Expand All @@ -21,30 +21,31 @@ type IPInfo struct {
var GlobalIPInfo IPInfo

func GetIPInfo() {
resp, err := http.Get("https://ipinfo.io")
resp, err := http.Get("https://ipinfo.io/json")
if err != nil {
fmt.Println("Error fetching IP information:", err)
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
fmt.Println("Error:", err)
return
}

if err := json.Unmarshal(body, &GlobalIPInfo); err != nil {
fmt.Println("Error unmarshaling JSON:", err)
err = json.Unmarshal(body, &GlobalIPInfo)
if err != nil {
fmt.Println("Error:", err)
return
}

fmt.Println("IP:", GlobalIPInfo.IP)
fmt.Println("City:", GlobalIPInfo.City)
fmt.Println("Region:", GlobalIPInfo.Region)
fmt.Println("Country:", GlobalIPInfo.Country)
fmt.Println("Location:", GlobalIPInfo.Location)
fmt.Println("Organization:", GlobalIPInfo.Org)
fmt.Println("Postal:", GlobalIPInfo.Postal)
fmt.Println("Timezone:", GlobalIPInfo.Timezone)
fmt.Printf("IP: %s\n", GlobalIPInfo.IP)
fmt.Printf("City: %s\n", GlobalIPInfo.City)
fmt.Printf("Region: %s\n", GlobalIPInfo.Region)
fmt.Printf("Country: %s\n", GlobalIPInfo.Country)
fmt.Printf("Location: %s\n", GlobalIPInfo.Location)
fmt.Printf("Organization: %s\n", GlobalIPInfo.Org)
fmt.Printf("Postal: %s\n", GlobalIPInfo.Postal)
fmt.Printf("Timezone: %s\n", GlobalIPInfo.Timezone)
}

0 comments on commit f85ea1b

Please sign in to comment.