68 Commits
mvp ... main

Author SHA1 Message Date
renovate[bot]
09fcce6be5 Update github/codeql-action action to v3 (#33)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-14 19:51:25 +00:00
renovate[bot]
cf40e0b6b5 Update actions/setup-go action to v5 (#32)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-10 14:46:22 +00:00
renovate[bot]
fddf51b7bf Roll back actions/checkout action to v4.1.1 (#31)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-10-18 12:09:57 +01:00
renovate[bot]
a72f303b68 Update actions/checkout digest to 8ade135 (#30)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-09-22 20:47:06 +01:00
renovate[bot]
f2607b5b4a Update actions/checkout action to v4 (#29)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-09-04 20:47:17 +01:00
renovate[bot]
5f4d044cb0 Update golang Docker tag to v1.21 (#28)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-11 18:15:38 +01:00
renovate[bot]
9d5b10625f Update golang Docker tag to v1.20 (#26)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-03-16 18:52:43 +00:00
renovate[bot]
e56baff565 Update actions/setup-go action to v4 (#27)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-03-16 18:30:18 +00:00
d056af8001 Create bug_report.yml 2023-01-10 22:45:02 +00:00
renovate[bot]
6ff1142ead Update actions/setup-go action to v3 (#23)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-08-13 21:59:57 +01:00
Luke Tainton
9725c985f5 Switch to SonarCloud (#25) 2022-08-13 21:57:09 +01:00
Luke Tainton
6db5904a31 Fix unit tests (#24) 2022-08-13 21:08:32 +01:00
Luke Tainton
d4c812f214 Add SonarQube and unit tests (#22) 2022-08-13 21:02:15 +01:00
Luke Tainton
c4de2f6025 Remove GitLab files (#21) 2022-08-13 14:47:08 +01:00
renovate[bot]
b38c70a425 Update module go to 1.19 (#18)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-08-07 19:05:49 +01:00
renovate[bot]
a0f4a7a262 Update dependency golang (#17)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-08-07 19:03:59 +01:00
renovate[bot]
a3a8f86885 Update module go to 1.18 (#16)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-07-31 15:40:10 +01:00
renovate[bot]
e140cc59f5 Update dependency golang to v1.18.2 (#11)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-05-21 15:42:19 +01:00
renovate[bot]
be0d38db70 Update dependency docker to v20 (#9)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-04-13 19:35:55 +01:00
Luke Tainton
1aba5c038c Create codeql-analysis.yml 2022-04-13 16:29:22 +01:00
renovate[bot]
1c5d01a492 Update dependency registry.gitlab.com/gitlab-org/release-cli to v0.11.0 (#7)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-04-13 16:28:08 +01:00
renovate[bot]
8332d6240d Update dependency docker to v19.03.15 (#5)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-04-13 16:28:00 +01:00
renovate[bot]
8133bc1058 Update actions/checkout action to v3 (#8)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-04-13 16:27:48 +01:00
Luke Tainton
dcfd3098a5 Update README.md 2022-04-13 16:25:49 +01:00
Luke Tainton
e1283d95e8 Replace SAST with DeepSource 2022-04-13 16:19:51 +01:00
Luke Tainton
20cbc0cbd4 Pin SAST to 1.0.2 2022-04-13 16:15:00 +01:00
Luke Tainton
39c839a33d Fix SAST 2022-04-13 15:47:50 +01:00
Luke Tainton
ebfbd41801 Fix SAST 2022-04-13 15:46:09 +01:00
Luke Tainton
2eaddcb743 Fix SAST 2022-04-13 15:32:39 +01:00
renovate[bot]
1ac46c0b22 Update dependency golang (#6)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-04-13 15:27:17 +01:00
Luke Tainton
d8480e8946 Move back to GitHub 2022-04-13 15:26:05 +01:00
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
849dc9b0ee v1.3.14 2021-11-20 22:39:09 +00:00
617d94add8 v1.3.13 2021-11-20 22:28:28 +00:00
427fa2ffed Update .gitlab-ci.yml file 2021-11-20 22:13:08 +00:00
7b7d706681 Move to GitLab 2021-11-20 22:08:05 +00:00
renovate[bot]
ebf0988f7d Update golang Docker tag to v1.17 (#3)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-10-19 22:49:07 +01:00
202e106486 Create workflow: auto-assign issues 2021-10-19 22:47:43 +01:00
3507540770 Merge branch 'main' of github.com:luketainton/iPilot 2021-03-07 16:53:59 +00:00
a4579b399e v1.3.10: Updated GHA flow 2021-03-07 16:53:37 +00:00
73c6eae26a Add repo URL to Dockerfile 2021-03-06 17:52:31 +00:00
renovate[bot]
eb0f36d314 Add renovate.json (#2)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-03-06 16:02:19 +00:00
7be52a79d6 v1.3.9: Migrate to new container registry 2021-03-06 15:50:42 +00:00
5f2e956e80 v1.3.8: Fix GitHub Actions build (7) 2021-03-06 15:35:38 +00:00
242137d421 v1.3.7: Fix GitHub Actions build (6) 2021-03-06 15:34:36 +00:00
0c2b7ae461 v1.3.6: Fix GitHub Actions build (5) 2021-03-06 15:33:40 +00:00
bb4d1439cf v1.3.5: Fix GitHub Actions build (4) 2021-03-06 15:27:21 +00:00
d8b07d11a1 v1.3.4: Fix GitHub Actions build (3) 2021-03-06 15:24:22 +00:00
3e75a5b445 v1.3.3: Fix GitHub Actions build (2) 2021-03-06 15:18:51 +00:00
46177264a1 v1.3.2: Fix GitHub Actions build 2021-03-06 15:15:49 +00:00
ec9e6ca83c Add Docker configuration 2021-03-06 15:11:40 +00:00
e1953f339d Version 1.3.1: [FIX] Allow disabling header 2021-02-19 23:33:19 +00:00
9d03c6f567 Version 1.3: Allow disabling header 2021-02-19 23:24:10 +00:00
e15b6d702c Update README.md 2021-02-09 12:06:08 +00:00
d96a91f161 Copy README from ltipinfo 2021-02-09 12:05:20 +00:00
3efe3882c1 Create LICENSE.md 2021-01-17 20:05:16 +00:00
Luke Tainton
e64ede67fb Version 1.2: Add error handling 2020-12-17 16:43:40 +00:00
d2f7dc9b0c Add function to get BGP advertised prefixes 2020-11-21 21:51:10 +00:00
18 changed files with 465 additions and 36 deletions

8
.deepsource.toml Normal file
View File

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

58
.github/ISSUE_TEMPLATE/bug_report.yml vendored Normal file
View File

@@ -0,0 +1,58 @@
---
name: "Bug Report"
description: "Submit a bug report"
labels: ["bug"]
assignees: ["luketainton"]
body:
- type: checkboxes
id: checks
attributes:
label: First Check
description: Please confirm and check all the following options.
options:
- label: This is not a feature request
required: true
- label: I added a descriptive title to this issue.
required: true
- label: I used the GitHub search to find a similar issue and didn't find one.
required: true
- type: input
id: ipilot-version
attributes:
label: iPilot Version
validations:
required: true
- type: textarea
id: description
attributes:
label: What is the issue you are experiencing?
placeholder: A clear and concise description of what the bug is.
validations:
required: true
- type: textarea
id: reproduction
attributes:
description: If you do not provide a way to reproduce the issue, your issue will likely be closed.
label: How can the maintainer reproduce the issue?
placeholder: A clear step-by-step guide on how to reproduce the issue.
validations:
required: true
- type: dropdown
id: os
attributes:
label: Deployment
description: What Deployment system are you using?
multiple: true
options:
- Docker
- Native (Windows)
- Native (MacOS)
- Native (Linux)
- Other
validations:
required: true
- type: textarea
id: os-details
attributes:
label: Deployment Details
description: You can add more details about your operating system here, in particular if you chose "Other".

63
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,63 @@
name: Build
on:
push:
tags: '*'
jobs:
prepare-data:
name: Prepare Data
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.prepare.outputs.SOURCE_TAG }}
repo: ${{ steps.prepare.outputs.REPO }}
lrepo: ${{ steps.prepare.outputs.LREPO }}
steps:
- id: prepare
name: Prepare environment variables
run: |
echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/}
echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/}
echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/}
echo ::set-output name=REPO::${GITHUB_REPOSITORY#luketainton/}
echo ::set-output name=LREPO::${GITHUB_REPOSITORY#luketainton/} | tr '[:upper:]' '[:lower:]'
docker:
name: GitHub Package Registry
runs-on: ubuntu-latest
needs: [prepare-data]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Login to GitHub Package Registry
run: echo ${{ secrets.PAT }} | docker login ghcr.io -u luketainton --password-stdin
- name: Build image for GitHub Package Registry
run: docker build . --file Dockerfile --tag ghcr.io/luketainton/${{ needs.prepare-data.outputs.lrepo }}:${{ needs.prepare-data.outputs.tag }} --tag ghcr.io/luketainton/${{ needs.prepare-data.outputs.lrepo }}:latest
- name: Push image to GitHub Package Registry
run: |
docker push ghcr.io/luketainton/${{ needs.prepare-data.outputs.lrepo }}:latest
docker push ghcr.io/luketainton/${{ needs.prepare-data.outputs.lrepo }}:${{ needs.prepare-data.outputs.tag }}
build:
name: Build and Release
runs-on: ubuntu-latest
needs: [prepare-data]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Build artifacts
run: |
docker run --rm -w /go/src/app -v ${PWD}:/go/src/app -e CGO_ENABLED=0 -e GOARCH=amd64 -e GOOS=darwin golang:alpine go build -o /go/src/app/${{ needs.prepare-data.outputs.repo }}-${{ needs.prepare-data.outputs.tag }}-darwin-amd64
docker run --rm -w /go/src/app -v ${PWD}:/go/src/app -e CGO_ENABLED=0 -e GOARCH=arm64 -e GOOS=darwin golang:alpine go build -o /go/src/app/${{ needs.prepare-data.outputs.repo }}-${{ needs.prepare-data.outputs.tag }}-darwin-arm64
docker run --rm -w /go/src/app -v ${PWD}:/go/src/app -e CGO_ENABLED=0 -e GOARCH=amd64 -e GOOS=linux golang:alpine go build -o /go/src/app/${{ needs.prepare-data.outputs.repo }}-${{ needs.prepare-data.outputs.tag }}-linux-amd64
docker run --rm -w /go/src/app -v ${PWD}:/go/src/app -e CGO_ENABLED=0 -e GOARCH=amd64 -e GOOS=windows golang:alpine go build -o /go/src/app/${{ needs.prepare-data.outputs.repo }}-${{ needs.prepare-data.outputs.tag }}-win-amd64.exe
docker run --rm -w /go/src/app -v ${PWD}:/go/src/app -e CGO_ENABLED=0 -e GOARCH=386 -e GOOS=windows golang:alpine go build -o /go/src/app/${{ needs.prepare-data.outputs.repo }}-${{ needs.prepare-data.outputs.tag }}-win-x86.exe
- uses: meeDamian/github-release@v2.0.3
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ needs.prepare-data.outputs.tag }}
gzip: false
files: >
${{ needs.prepare-data.outputs.repo }}-${{ needs.prepare-data.outputs.tag }}-darwin-amd64
${{ needs.prepare-data.outputs.repo }}-${{ needs.prepare-data.outputs.tag }}-darwin-arm64
${{ needs.prepare-data.outputs.repo }}-${{ needs.prepare-data.outputs.tag }}-linux-amd64
${{ needs.prepare-data.outputs.repo }}-${{ needs.prepare-data.outputs.tag }}-win-amd64.exe
${{ needs.prepare-data.outputs.repo }}-${{ needs.prepare-data.outputs.tag }}-win-x86.exe

70
.github/workflows/codeql-analysis.yml vendored Normal file
View File

@@ -0,0 +1,70 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '18 1 * * 1'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

15
.github/workflows/issues.yml vendored Normal file
View File

@@ -0,0 +1,15 @@
name: Issue assignment
on:
issues:
types: [opened]
jobs:
auto-assign:
runs-on: ubuntu-latest
steps:
- name: 'Auto-assign issue'
uses: pozil/auto-assign-issue@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
assignees: luketainton

42
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,42 @@
name: Test
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches: [ main ]
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.19
- name: Create golangci-lint report
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.42.1
$(go env GOPATH)/bin/golangci-lint run --out-format checkstyle -D deadcode,unused --build-tags=integration --timeout 10m --issues-exit-code 0 ./... > report.xml
sed -i 's+<file name="+<file name="go/+g' report.xml
cat report.xml
- name: Test
run: go test -short -coverprofile=coverage.out
continue-on-error: true
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_CLOUD }}
# - uses: sonarsource/sonarqube-scan-action@master
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
# - uses: sonarsource/sonarqube-quality-gate-action@master
# timeout-minutes: 5
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/.vscode
/.idea

55
API.go
View File

@@ -1,26 +1,67 @@
package main package main
import ( import (
"encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"net" "net"
"net/http" "net/http"
"os"
"sort"
"strings"
) )
func getLocalIP() string { func getLocalIP() string {
resp, _ := http.Get("https://api.ipify.org") resp, err := http.Get("https://api.ipify.org")
if err != nil {
fmt.Println("FATAL: Cannot get local IP.")
os.Exit(2)
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 {
address, _ := net.LookupHost(hostname) address, _ := net.LookupHost(hostname)
return address[0] return address[0]
} }
func getIPInfo(ipaddress string) IPAddressInfo {
apiEndpoint := "http://ip-api.com/json/" + ipaddress
resp, err := http.Get(apiEndpoint)
if err != nil {
fmt.Println("FATAL: Cannot contact IP address information API.")
os.Exit(3)
}
body, _ := ioutil.ReadAll(resp.Body)
infoString := string(body)
var info IPAddressInfo
err = json.Unmarshal([]byte(infoString), &info)
if err != nil {
fmt.Println("FATAL: Cannot serialize recieved IP address data.")
os.Exit(4)
}
return info
}
func printBGPPrefixes(as string) {
apiEndpoint := "https://api.hackertarget.com/aslookup/?q=" + as
resp, err := http.Get(apiEndpoint)
if err != nil {
fmt.Println("FATAL: Cannot contact BGP Prefixes API.")
os.Exit(5)
}
body, _ := ioutil.ReadAll(resp.Body)
prefixesString := string(body)
var prefixes = strings.Split(prefixesString, "\n")[1:]
sort.Strings(prefixes)
for index := range prefixes {
fmt.Println(prefixes[index])
}
}

10
Dockerfile Normal file
View File

@@ -0,0 +1,10 @@
FROM golang:1.21-alpine as build
WORKDIR /go/src/app
COPY . /go/src/app
RUN CGO_ENABLED=0 go build -o /go/bin/app
FROM gcr.io/distroless/base-debian10
LABEL maintainer="Luke Tainton <luke@tainton.uk>"
LABEL org.opencontainers.image.source="https://github.com/luketainton/iPilot"
COPY --from=build /go/bin/app /
CMD ["/app"]

View File

@@ -11,4 +11,5 @@ func printHeader() {
fmt.Println("| By Luke Tainton |") fmt.Println("| By Luke Tainton |")
fmt.Println("| @luketainton |") fmt.Println("| @luketainton |")
fmt.Println("------------------------------") fmt.Println("------------------------------")
fmt.Println("")
} }

View File

@@ -1,10 +1,7 @@
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"io/ioutil"
"net/http"
"strings" "strings"
) )
@@ -26,26 +23,17 @@ type IPAddressInfo struct {
IPAddress string `json:"query"` IPAddress string `json:"query"`
} }
func getIPInfo(ipaddress string) IPAddressInfo { func printIPInfo(input string, wantPrefixes bool) {
apiEndpoint := "http://ip-api.com/json/" + ipaddress
resp, _ := http.Get(apiEndpoint)
body, _ := ioutil.ReadAll(resp.Body)
// fmt.Print(string(body))
infoString := string(body)
var info IPAddressInfo
err := json.Unmarshal([]byte(infoString), &info)
if err != nil {
fmt.Println(err)
}
return info
}
func printIPInfo(input string) {
var IPInfo IPAddressInfo = getIPInfo(input) var IPInfo IPAddressInfo = getIPInfo(input)
var location string = IPInfo.Country + "/" + IPInfo.RegionName + "/" + IPInfo.City var location string = IPInfo.Country + "/" + IPInfo.RegionName + "/" + IPInfo.City
var bgpAS string = strings.Fields(IPInfo.AS)[0]
fmt.Println("IP Address: ", IPInfo.IPAddress) fmt.Println("IP Address: ", IPInfo.IPAddress)
fmt.Println("Location: ", location) fmt.Println("Location: ", location)
fmt.Println("Timezone: ", IPInfo.Timezone) fmt.Println("Timezone: ", IPInfo.Timezone)
fmt.Println("ISP: ", IPInfo.ISP) fmt.Println("ISP: ", IPInfo.ISP)
fmt.Println("BGP AS: ", strings.Fields(IPInfo.AS)[0]) fmt.Println("BGP AS: ", bgpAS)
if wantPrefixes {
fmt.Println("\nBGP Prefixes:")
printBGPPrefixes(bgpAS)
}
} }

21
LICENSE.md Normal file
View File

@@ -0,0 +1,21 @@
MIT License
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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

48
Main.go
View File

@@ -3,23 +3,51 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"os"
) )
func main() { func main() {
printHeader()
var input string var input string
localIPAddress := getLocalIP() var wantPrefixes bool
flag.StringVar(&input, "i", localIPAddress, "Specify IP address or domain name.") var wantHeader bool
flag.StringVar(&input, "i", "", "IP address or domain")
flag.BoolVar(&wantPrefixes, "p", false, "print BGP prefixes")
flag.BoolVar(&wantHeader, "b", true, "enable/disable header")
flag.Usage = func() {
fmt.Printf("Usage of iPilot: \n")
fmt.Printf("Example: iPilot -b=false -i=me -p \n")
fmt.Printf(" -b bool enable/disable header (default true)\n")
fmt.Printf(" -h bool view help\n")
fmt.Printf(" -i string IP address or domain\n")
fmt.Printf(" -p bool print BGP prefixes (default false)\n")
}
flag.Parse() flag.Parse()
var isIPCorrect bool = checkIPSyntax(input)
if isIPCorrect == true { if wantHeader {
printIPInfo(input) printHeader()
}
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 { } else {
// fmt.Println(ipaddress, "is not a valid IP address.")
fmt.Println("Domain Name: ", input)
ipaddress := resolveDNSHostname(input) ipaddress := resolveDNSHostname(input)
printIPInfo(ipaddress) if isIPAddress(ipaddress) {
fmt.Println("Domain Name: ", input)
printIPInfo(ipaddress, wantPrefixes)
} else {
fmt.Println("Invalid query.")
}
} }
} }

23
README.md Normal file
View File

@@ -0,0 +1,23 @@
# IP Information Lookup Tool (iPilot)
This Go application takes an IP address or domain name and gathers the following information:
- Location
- Timezone
- Internet Service Provider
- Autonomous System
- Advertised Prefixes
## Running the script
Here are some ways that you can run the script:
| Command | Description |
| ---------------------- | ---------------------------------------- |
| `./iPilot -i me` | Run against your own connection |
| `./iPilot -i 1.1.1.1` | Run against the IP address `1.1.1.1` |
| `./iPilot -i google.com` | Run against the domain name `google.com` |
| `./iPilot -i google.com -p` | Run against the domain name `google.com` and lists BGP prefixes |
## Support
For support please open an issue on [GitLab](https://gitlab.com/luketainton/iPilot) or email [ipilot@help.tainton.uk](mailto:ipilot@help.tainton.uk).
## Credits
This script runs thanks to the APIs provided by [IP-API](http://ip-api.com) and [HackerTarget](https://hackertarget.com/as-ip-lookup).

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module github.com/luketainton/iPilot
go 1.19

29
ipilot_test.go Normal file
View File

@@ -0,0 +1,29 @@
package main
import "testing"
func TestGetCurrentIP(t *testing.T) {
myip := getLocalIP()
if myip == "" {
t.Log("could not retrieve current IP")
t.Fail()
}
}
func TestIsIPAddress(t *testing.T) {
ipaddress := "192.168.0.1"
isIP := isIPAddress(ipaddress)
if isIP == false {
t.Log("could not verify " + ipaddress + " is an IP address")
t.Fail()
}
}
func TestResolveDNSHostname(t *testing.T) {
hostname := "one.one.one.one"
ipaddress := resolveDNSHostname(hostname)
if ipaddress != "1.1.1.1" {
t.Log("could not resolve IP for " + hostname)
t.Fail()
}
}

16
renovate.json Normal file
View File

@@ -0,0 +1,16 @@
{
"extends": ["config:base"],
"platformCommit": true,
"dependencyDashboardAutoclose": true,
"assignAutomerge": true,
"assigneesFromCodeOwners": true,
"rebaseWhen": "behind-base-branch",
"rollbackPrs": true,
"labels": ["dependencies"],
"vulnerabilityAlerts": {
"enabled": true,
"labels": ["security"],
"commitMessagePrefix": "[SECURITY] ",
"prCreation": "immediate"
}
}

11
sonar-project.properties Normal file
View File

@@ -0,0 +1,11 @@
sonar.organization=luketainton
sonar.projectKey=luketainton_iPilot
# sonar.projectKey=luketainton_iPilot_AYKYmHI397IDIMpeRtF7
sonar.projectName=iPilot
sonar.projectVersion=1.3.9
sonar.sources=.
sonar.exclusions=,.github/**,.gitignore,CODEOWNERS,CHANGELOG.md,LICENSE.md,README.md,renovate.json,**/*_test.go
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.go.golangci-lint.reportPaths=report.xml
sonar.go.coverage.reportPaths=coverage.out