Fix DeepSource issues
This commit is contained in:
11
API.go
11
API.go
@@ -19,15 +19,12 @@ func getLocalIP() string {
|
||||
return ""
|
||||
}
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
return string(body[:])
|
||||
return string(body)
|
||||
}
|
||||
|
||||
func checkIPSyntax(ipaddress string) bool {
|
||||
func isIPAddress(ipaddress string) bool {
|
||||
addr := net.ParseIP(ipaddress)
|
||||
if addr == nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return addr != nil
|
||||
}
|
||||
|
||||
func resolveDNSHostname(hostname string) string {
|
||||
@@ -53,7 +50,7 @@ func getIPInfo(ipaddress string) IPAddressInfo {
|
||||
return info
|
||||
}
|
||||
|
||||
func getBGPPrefixes(as string) {
|
||||
func printBGPPrefixes(as string) {
|
||||
apiEndpoint := "https://api.hackertarget.com/aslookup/?q=" + as
|
||||
resp, err := http.Get(apiEndpoint)
|
||||
if err != nil {
|
||||
|
||||
@@ -32,8 +32,8 @@ func printIPInfo(input string, wantPrefixes bool) {
|
||||
fmt.Println("Timezone: ", IPInfo.Timezone)
|
||||
fmt.Println("ISP: ", IPInfo.ISP)
|
||||
fmt.Println("BGP AS: ", bgpAS)
|
||||
if wantPrefixes == true {
|
||||
if wantPrefixes {
|
||||
fmt.Println("\nBGP Prefixes:")
|
||||
getBGPPrefixes(bgpAS)
|
||||
printBGPPrefixes(bgpAS)
|
||||
}
|
||||
}
|
||||
|
||||
25
Main.go
25
Main.go
@@ -33,21 +33,20 @@ func main() {
|
||||
if input == "" {
|
||||
fmt.Println("FATAL: No IP address or domain name was specified.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if input == "me" {
|
||||
input = getLocalIP()
|
||||
}
|
||||
if isIPAddress(input) {
|
||||
printIPInfo(input, wantPrefixes)
|
||||
} else {
|
||||
if input == "me" {
|
||||
input = getLocalIP()
|
||||
}
|
||||
var isIPCorrect bool = checkIPSyntax(input)
|
||||
if isIPCorrect == true {
|
||||
printIPInfo(input, wantPrefixes)
|
||||
ipaddress := resolveDNSHostname(input)
|
||||
if isIPAddress(ipaddress) {
|
||||
fmt.Println("Domain Name: ", input)
|
||||
printIPInfo(ipaddress, wantPrefixes)
|
||||
} else {
|
||||
ipaddress := resolveDNSHostname(input)
|
||||
if checkIPSyntax(ipaddress) == true {
|
||||
fmt.Println("Domain Name: ", input)
|
||||
printIPInfo(ipaddress, wantPrefixes)
|
||||
} else {
|
||||
fmt.Println("Invalid query.")
|
||||
}
|
||||
fmt.Println("Invalid query.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user