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

25
Main.go
View File

@@ -33,21 +33,20 @@ 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)
}
if input == "me" {
input = getLocalIP()
}
if isIPAddress(input) {
printIPInfo(input, wantPrefixes)
} else { } else {
if input == "me" { ipaddress := resolveDNSHostname(input)
input = getLocalIP() if isIPAddress(ipaddress) {
} fmt.Println("Domain Name: ", input)
var isIPCorrect bool = checkIPSyntax(input) printIPInfo(ipaddress, wantPrefixes)
if isIPCorrect == true {
printIPInfo(input, wantPrefixes)
} else { } else {
ipaddress := resolveDNSHostname(input) fmt.Println("Invalid query.")
if checkIPSyntax(ipaddress) == true {
fmt.Println("Domain Name: ", input)
printIPInfo(ipaddress, wantPrefixes)
} else {
fmt.Println("Invalid query.")
}
} }
} }