Add function to get BGP advertised prefixes
This commit is contained in:
23
IPInfo.go
23
IPInfo.go
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -30,7 +31,6 @@ func getIPInfo(ipaddress string) IPAddressInfo {
|
||||
apiEndpoint := "http://ip-api.com/json/" + ipaddress
|
||||
resp, _ := http.Get(apiEndpoint)
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
// fmt.Print(string(body))
|
||||
infoString := string(body)
|
||||
var info IPAddressInfo
|
||||
err := json.Unmarshal([]byte(infoString), &info)
|
||||
@@ -40,12 +40,29 @@ func getIPInfo(ipaddress string) IPAddressInfo {
|
||||
return info
|
||||
}
|
||||
|
||||
func printIPInfo(input string) {
|
||||
func getBGPPrefixes(as string) {
|
||||
apiEndpoint := "https://api.hackertarget.com/aslookup/?q=" + as
|
||||
resp, _ := http.Get(apiEndpoint)
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
prefixesString := string(body)
|
||||
var prefixes = strings.Split(prefixesString, "\n")[1:]
|
||||
sort.Strings(prefixes)
|
||||
for i := 0; i < len(prefixes); i++ {
|
||||
fmt.Println(prefixes[i])
|
||||
}
|
||||
}
|
||||
|
||||
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: ", strings.Fields(IPInfo.AS)[0])
|
||||
fmt.Println("BGP AS: ", bgpAS)
|
||||
if wantPrefixes == true {
|
||||
fmt.Println("\nBGP Prefixes:")
|
||||
getBGPPrefixes(bgpAS)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user