-
Notifications
You must be signed in to change notification settings - Fork 6
/
NSchecker.go
74 lines (60 loc) · 1.64 KB
/
NSchecker.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"flag"
"nschecker/checker"
"nschecker/notification"
"nschecker/printer"
"os"
)
var VERSION = "1.0.2"
func showError() {
printer.ErrorPrintf("USAGE: go run NsCheck.go -type NS -domain domainName -expect 'ns records' \n")
printer.ErrorPrintf(" or \n")
printer.ErrorPrintf("USAGE (Deplicated): go run NsCheck.go type(NS or MX) 'domain' 'ns records' \n")
os.Exit(1)
}
func main() {
var qType string
var domainName string
var nsListString string
if len(os.Args) < 4 {
showVersion()
showError()
}
if len(os.Args) != 4 {
qType2 := flag.String("type", "NS", "type: NS or MX")
domainName2 := flag.String("domain", "", "domain name: vaddy.net")
nsListString2 := flag.String("expect", "", "ex: 'ns1.vaddy.net, ns2.vaddy.net'")
mode := flag.String("mode", "", "optional: silent")
flag.Parse()
qType = *qType2
domainName = *domainName2
nsListString = *nsListString2
if *mode == "silent" {
printer.SilentModeOn()
}
} else {
qType = os.Args[1]
domainName = os.Args[2]
nsListString = os.Args[3]
}
showVersion()
if qType != "NS" && qType != "MX" {
showError()
}
infoDump(domainName, qType, nsListString)
err := checker.CheckRecord(qType, domainName, nsListString)
if err != nil {
notification.PostSlack("NSchecker (Ver. "+VERSION+")", err.Error(), domainName, qType)
panic(err)
}
}
func infoDump(domainName string, qType string, nsListString string) {
printer.Printf(" - Domain: %s\n", domainName)
printer.Printf(" - Type: %s\n", qType)
printer.Printf(" - List: %s\n", nsListString)
printer.Printf("")
}
func showVersion() {
printer.Printf("=== NSchecker Version: %s === \n", VERSION)
}