3 Commits

Author SHA1 Message Date
6c88bbf40a Add DeepSource config 2022-02-11 15:18:50 +00:00
c64f489c95 Fix DeepSource issues 2022-02-11 15:17:03 +00:00
911cfef9e7 Add .deepsource.toml 2022-02-11 14:53:40 +00:00
4 changed files with 26 additions and 22 deletions

8
.deepsource.toml Normal file
View File

@@ -0,0 +1,8 @@
version = 1
[[analyzers]]
name = "go"
enabled = true
[analyzers.meta]
import_root = "gitlab.com/luketainton/iPilot"

11
API.go
View File

@@ -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 {

View File

@@ -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
View File

@@ -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.")
}
}