Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d03c6f567 | |||
| e15b6d702c | |||
| d96a91f161 | |||
| 3efe3882c1 | |||
|
|
e64ede67fb | ||
| d2f7dc9b0c |
46
API.go
46
API.go
@@ -1,13 +1,23 @@
|
|||||||
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[:])
|
||||||
}
|
}
|
||||||
@@ -24,3 +34,37 @@ 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 getBGPPrefixes(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])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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("")
|
||||||
}
|
}
|
||||||
|
|||||||
29
IPInfo.go
29
IPInfo.go
@@ -1,10 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"net/http"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,26 +24,19 @@ 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)
|
||||||
|
fmt.Printf("%+v\n", IPInfo)
|
||||||
|
os.Exit(200)
|
||||||
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 == true {
|
||||||
|
fmt.Println("\nBGP Prefixes:")
|
||||||
|
getBGPPrefixes(bgpAS)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
LICENSE.md
Normal file
21
LICENSE.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 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.
|
||||||
50
Main.go
50
Main.go
@@ -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(" -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)
|
||||||
} else {
|
} else {
|
||||||
// fmt.Println(ipaddress, "is not a valid IP address.")
|
if input == "me" {
|
||||||
fmt.Println("Domain Name: ", input)
|
input = getLocalIP()
|
||||||
ipaddress := resolveDNSHostname(input)
|
}
|
||||||
printIPInfo(ipaddress)
|
var isIPCorrect bool = checkIPSyntax(input)
|
||||||
|
if isIPCorrect == true {
|
||||||
|
printIPInfo(input, wantPrefixes)
|
||||||
|
} else {
|
||||||
|
ipaddress := resolveDNSHostname(input)
|
||||||
|
if checkIPSyntax(ipaddress) == true {
|
||||||
|
fmt.Println("Domain Name: ", input)
|
||||||
|
printIPInfo(ipaddress, wantPrefixes)
|
||||||
|
} else {
|
||||||
|
fmt.Println("Invalid query.")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
20
README.md
Normal file
20
README.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# 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 |
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
This script runs thanks to the APIs provided by [IP-API](http://ip-api.com) and [HackerTarget](https://hackertarget.com/as-ip-lookup).
|
||||||
Reference in New Issue
Block a user