11 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
d38a7e126d Move to GitLab, update minimum Go version 2022-01-05 22:34:45 +00:00
858b11ba23 Merge branch 'set-sast-config-1' into 'main'
Configure SAST in `.gitlab-ci.yml`, creating this file if it does not already exist

See merge request luketainton/iPilot!4
2021-11-20 23:29:00 +00:00
f60ffe3525 Configure SAST in .gitlab-ci.yml, creating this file if it does not already exist 2021-11-20 23:29:00 +00:00
a10c6f76d3 v1.3.19 2021-11-20 23:11:07 +00:00
5d5f096033 v1.3.18 2021-11-20 23:00:28 +00:00
b8dc73a720 v1.3.17 2021-11-20 22:58:03 +00:00
27280e8d45 v1.3.16 2021-11-20 22:43:06 +00:00
8c5e12960d v1.3.15 2021-11-20 22:41:52 +00:00
8 changed files with 85 additions and 70 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"

View File

@@ -1,72 +1,80 @@
stages:
- build-docker
- build-binary
- upload
- release
- test
- build
- upload
- release
sast:
stage: test
include:
- template: Security/SAST.gitlab-ci.yml
build-docker:
stage: build-docker
stage: build
only:
- tags
- tags
image: docker:19.03.12
services:
- docker:19.03.12-dind
- docker:19.03.12-dind
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
IMAGE_TAG: "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG"
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $CI_REGISTRY_IMAGE:latest -t $IMAGE_TAG .
- docker build -t $IMAGE_TAG -t $CI_REGISTRY_IMAGE:latest .
- docker push $IMAGE_TAG
- docker push $CI_REGISTRY_IMAGE:latest
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $CI_REGISTRY_IMAGE:latest -t $IMAGE_TAG .
- docker build -t $IMAGE_TAG -t $CI_REGISTRY_IMAGE:latest .
- docker push $IMAGE_TAG
- docker push $CI_REGISTRY_IMAGE:latest
build-binary:
stage: build-binary
stage: build
only:
- tags
- tags
image: golang:1.17.3
before_script:
- cd $GOPATH/src
- mkdir -p gitlab.com/$CI_PROJECT_NAMESPACE
- cd gitlab.com/$CI_PROJECT_NAMESPACE
- ln -s $CI_PROJECT_DIR
- cd $CI_PROJECT_NAME
- cd $GOPATH/src
- mkdir -p gitlab.com/$CI_PROJECT_NAMESPACE
- cd gitlab.com/$CI_PROJECT_NAMESPACE
- ln -s $CI_PROJECT_DIR
- cd $CI_PROJECT_NAME
script:
- CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -o iPilot-${CI_COMMIT_TAG}-darwin-amd64
- CGO_ENABLED=0 GOARCH=arm64 GOOS=darwin go build -o iPilot-${CI_COMMIT_TAG}-darwin-arm64
- CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o iPilot-${CI_COMMIT_TAG}-linux-amd64
- CGO_ENABLED=0 GOARCH=amd64 GOOS=windows go build -o iPilot-${CI_COMMIT_TAG}-win-amd64.exe
- CGO_ENABLED=0 GOARCH=386 GOOS=windows go build -o iPilot-${CI_COMMIT_TAG}-win-x86.exe
- CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -o bin/iPilot-${CI_COMMIT_TAG}-darwin-amd64
- CGO_ENABLED=0 GOARCH=arm64 GOOS=darwin go build -o bin/iPilot-${CI_COMMIT_TAG}-darwin-arm64
- CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o bin/iPilot-${CI_COMMIT_TAG}-linux-amd64
- CGO_ENABLED=0 GOARCH=amd64 GOOS=windows go build -o bin/iPilot-${CI_COMMIT_TAG}-win-amd64.exe
- CGO_ENABLED=0 GOARCH=386 GOOS=windows go build -o bin/iPilot-${CI_COMMIT_TAG}-win-x86.exe
artifacts:
paths:
- bin/
upload:
stage: upload
only:
- tags
image: curlimages/curl:latest
rules:
- if: $CI_COMMIT_TAG
before_script:
- ls
- pwd
- if: "$CI_COMMIT_TAG"
dependencies:
- build-binary
script:
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file iPilot-${CI_COMMIT_TAG}-darwin-amd64 "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-darwin-amd64"'
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file iPilot-${CI_COMMIT_TAG}-darwin-arm64 "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-darwin-arm64"'
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file iPilot-${CI_COMMIT_TAG}-linux-amd64 "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-linux-amd64"'
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file iPilot-${CI_COMMIT_TAG}-win-amd64.exe "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-win-amd64.exe"'
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file iPilot-${CI_COMMIT_TAG}-win-x86.exe "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-win-x86.exe"'
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file bin/iPilot-${CI_COMMIT_TAG}-darwin-amd64
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-darwin-amd64"'
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file bin/iPilot-${CI_COMMIT_TAG}-darwin-arm64
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-darwin-arm64"'
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file bin/iPilot-${CI_COMMIT_TAG}-linux-amd64
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-linux-amd64"'
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file bin/iPilot-${CI_COMMIT_TAG}-win-amd64.exe
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-win-amd64.exe"'
- 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file bin/iPilot-${CI_COMMIT_TAG}-win-x86.exe
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-win-x86.exe"'
release:
stage: release
only:
- tags
image: registry.gitlab.com/gitlab-org/release-cli:v0.4.0
rules:
- if: $CI_COMMIT_TAG
- if: "$CI_COMMIT_TAG"
script:
- |
release-cli create --name "$CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \
--assets-link "{\"name\":\"iPilot-${CI_COMMIT_TAG}-darwin-amd64\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-darwin-amd64\"}" \
--assets-link "{\"name\":\"iPilot-${CI_COMMIT_TAG}-darwin-arm64\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-darwin-arm64\"}" \
--assets-link "{\"name\":\"iPilot-${CI_COMMIT_TAG}-linux-amd64\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-linux-amd64\"}" \
--assets-link "{\"name\":\"iPilot-${CI_COMMIT_TAG}-win-amd64.exe\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-win-amd64.exe\"}" \
--assets-link "{\"name\":\"iPilot-${CI_COMMIT_TAG}-win-x86.exe\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-win-x86.exe\"}"
- |
release-cli create --name "$CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \
--assets-link "{\"name\":\"iPilot-${CI_COMMIT_TAG}-darwin-amd64\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-darwin-amd64\"}" \
--assets-link "{\"name\":\"iPilot-${CI_COMMIT_TAG}-darwin-arm64\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-darwin-arm64\"}" \
--assets-link "{\"name\":\"iPilot-${CI_COMMIT_TAG}-linux-amd64\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-linux-amd64\"}" \
--assets-link "{\"name\":\"iPilot-${CI_COMMIT_TAG}-win-amd64.exe\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-win-amd64.exe\"}" \
--assets-link "{\"name\":\"iPilot-${CI_COMMIT_TAG}-win-x86.exe\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/iPilot/${CI_COMMIT_TAG}/iPilot-${CI_COMMIT_TAG}-win-x86.exe\"}"

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

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021 Luke Tainton
Copyright (c) 2022 Luke Tainton
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

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

View File

@@ -21,3 +21,6 @@ For support please open an issue on [GitLab](https://gitlab.com/luketainton/iPil
## Credits
This script runs thanks to the APIs provided by [IP-API](http://ip-api.com) and [HackerTarget](https://hackertarget.com/as-ip-lookup).
## MOVED TO GITLAB
This repository has moved to [GitLab](https://gitlab.com/luketainton/iPilot). All future commits will be mirrored back to GitHub, but changes will only be accepted on the GitLab repository.

2
go.mod
View File

@@ -1,3 +1,3 @@
module github.com/luketainton/iPilot
go 1.16
go 1.17