Fix DeepSource issues

This commit is contained in:
2022-02-11 15:17:03 +00:00
parent d38a7e126d
commit c64f489c95
3 changed files with 18 additions and 22 deletions

11
API.go
View File

@@ -19,15 +19,12 @@ func getLocalIP() string {
return "" return ""
} }
body, _ := ioutil.ReadAll(resp.Body) 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) addr := net.ParseIP(ipaddress)
if addr == nil { return addr != nil
return false
}
return true
} }
func resolveDNSHostname(hostname string) string { func resolveDNSHostname(hostname string) string {
@@ -53,7 +50,7 @@ func getIPInfo(ipaddress string) IPAddressInfo {
return info return info
} }
func getBGPPrefixes(as string) { func printBGPPrefixes(as string) {
apiEndpoint := "https://api.hackertarget.com/aslookup/?q=" + as apiEndpoint := "https://api.hackertarget.com/aslookup/?q=" + as
resp, err := http.Get(apiEndpoint) resp, err := http.Get(apiEndpoint)
if err != nil { if err != nil {

View File

@@ -32,8 +32,8 @@ func printIPInfo(input string, wantPrefixes bool) {
fmt.Println("Timezone: ", IPInfo.Timezone) fmt.Println("Timezone: ", IPInfo.Timezone)
fmt.Println("ISP: ", IPInfo.ISP) fmt.Println("ISP: ", IPInfo.ISP)
fmt.Println("BGP AS: ", bgpAS) fmt.Println("BGP AS: ", bgpAS)
if wantPrefixes == true { if wantPrefixes {
fmt.Println("\nBGP Prefixes:") fmt.Println("\nBGP Prefixes:")
getBGPPrefixes(bgpAS) printBGPPrefixes(bgpAS)
} }
} }

View File

@@ -33,22 +33,21 @@ func main() {
if input == "" { if input == "" {
fmt.Println("FATAL: No IP address or domain name was specified.") fmt.Println("FATAL: No IP address or domain name was specified.")
os.Exit(1) os.Exit(1)
} else { }
if input == "me" { if input == "me" {
input = getLocalIP() input = getLocalIP()
} }
var isIPCorrect bool = checkIPSyntax(input) if isIPAddress(input) {
if isIPCorrect == true {
printIPInfo(input, wantPrefixes) printIPInfo(input, wantPrefixes)
} else { } else {
ipaddress := resolveDNSHostname(input) ipaddress := resolveDNSHostname(input)
if checkIPSyntax(ipaddress) == true { if isIPAddress(ipaddress) {
fmt.Println("Domain Name: ", input) fmt.Println("Domain Name: ", input)
printIPInfo(ipaddress, wantPrefixes) printIPInfo(ipaddress, wantPrefixes)
} else { } else {
fmt.Println("Invalid query.") fmt.Println("Invalid query.")
} }
} }
}
} }