-
Notifications
You must be signed in to change notification settings - Fork 0
/
IPInfo.go
39 lines (36 loc) · 1.13 KB
/
IPInfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"fmt"
"strings"
)
// IPAddressInfo is the IP Address information from API
type IPAddressInfo struct {
Status string `json:"status"`
Country string `json:"country"`
CountryCode string `json:"countryCode"`
Region string `json:"region"`
RegionName string `json:"regionName"`
City string `json:"city"`
ZIP string `json:"zip"`
Latitude float32 `json:"lat"`
Longitude float32 `json:"lon"`
Timezone string `json:"timezone"`
ISP string `json:"isp"`
Organisation string `json:"org"`
AS string `json:"as"`
IPAddress string `json:"query"`
}
func printIPInfo(input string, wantPrefixes bool) {
var IPInfo IPAddressInfo = getIPInfo(input)
var location string = IPInfo.Country + "/" + IPInfo.RegionName + "/" + IPInfo.City
var bgpAS string = strings.Fields(IPInfo.AS)[0]
fmt.Println("IP Address: ", IPInfo.IPAddress)
fmt.Println("Location: ", location)
fmt.Println("Timezone: ", IPInfo.Timezone)
fmt.Println("ISP: ", IPInfo.ISP)
fmt.Println("BGP AS: ", bgpAS)
if wantPrefixes {
fmt.Println("\nBGP Prefixes:")
printBGPPrefixes(bgpAS)
}
}