Version 1.2: Add error handling
This commit is contained in:
30
Main.go
30
Main.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -10,20 +11,29 @@ func main() {
|
||||
|
||||
var input string
|
||||
var wantPrefixes bool
|
||||
localIPAddress := getLocalIP()
|
||||
flag.StringVar(&input, "i", localIPAddress, "Specify IP address or domain name.")
|
||||
|
||||
flag.StringVar(&input, "i", "", "Specify IP address or domain name.")
|
||||
flag.BoolVar(&wantPrefixes, "p", false, "Enable printing of advertised BGP prefixes.")
|
||||
flag.Parse()
|
||||
var isIPCorrect bool = checkIPSyntax(input)
|
||||
if isIPCorrect == true {
|
||||
printIPInfo(input, wantPrefixes)
|
||||
|
||||
if input == "" {
|
||||
fmt.Println("FATAL: No IP address or domain name was specified.")
|
||||
os.Exit(1)
|
||||
} else {
|
||||
ipaddress := resolveDNSHostname(input)
|
||||
if checkIPSyntax(ipaddress) == true {
|
||||
fmt.Println("Domain Name: ", input)
|
||||
printIPInfo(ipaddress, wantPrefixes)
|
||||
if input == "me" {
|
||||
input = getLocalIP()
|
||||
}
|
||||
var isIPCorrect bool = checkIPSyntax(input)
|
||||
if isIPCorrect == true {
|
||||
printIPInfo(input, wantPrefixes)
|
||||
} else {
|
||||
fmt.Println("Invalid query.")
|
||||
ipaddress := resolveDNSHostname(input)
|
||||
if checkIPSyntax(ipaddress) == true {
|
||||
fmt.Println("Domain Name: ", input)
|
||||
printIPInfo(ipaddress, wantPrefixes)
|
||||
} else {
|
||||
fmt.Println("Invalid query.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user