-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.go
53 lines (44 loc) · 1.09 KB
/
Main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"flag"
"fmt"
"os"
)
func main() {
var input string
var wantPrefixes bool
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()
if wantHeader {
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 {
ipaddress := resolveDNSHostname(input)
if isIPAddress(ipaddress) {
fmt.Println("Domain Name: ", input)
printIPInfo(ipaddress, wantPrefixes)
} else {
fmt.Println("Invalid query.")
}
}
}