Skip to content

Commit b7b41ac

Browse files
committed
+whois.go
1 parent 0884e54 commit b7b41ac

File tree

2 files changed

+28
-36
lines changed

2 files changed

+28
-36
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ jobs:
3030
- run: go get -u github.com/tcnksm/ghr
3131
- run: go get -u github.com/stevenmatthewt/semantics
3232
- run: go get -u github.com/urfave/cli
33-
- run: go get -u golang.org/x/net/publicsuffix
33+
- run: go get -u github.com/likexian/whois-go
34+
- run: go get -u github.com/likexian/whois-parser-go
3435
- run:
3536
name: cross compile
3637
command: |

whoiz.go

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import (
99
"log"
1010
"io/ioutil"
1111
"os"
12-
"bytes"
13-
"os/exec"
1412
"github.com/urfave/cli"
15-
"golang.org/x/net/publicsuffix"
13+
"github.com/likexian/whois-go"
14+
"github.com/likexian/whois-parser-go"
1615
)
1716

1817
//////////
@@ -34,55 +33,47 @@ func main() {
3433
app.Action = func(c *cli.Context) error {
3534
domainName := string(c.Args().Get(0))
3635

37-
tldomain, _ := publicsuffix.EffectiveTLDPlusOne(domainName)
38-
if ( len(tldomain) <= 1 ){
39-
println ("Invalid domain provided!");
40-
return nil; //Lets not proceed without a valid TLD
41-
}
42-
4336

44-
cmd := exec.Command("bash","-c","whois "+tldomain+"| head -n10")
45-
//todo is there a golib for whois?
46-
cmdOutput := &bytes.Buffer{}
47-
cmd.Stdout = cmdOutput
37+
fmt.Printf("\nDomain Reg:")
38+
whoisResult, err := whois.Whois(domainName)
39+
result, err := whoisparser.Parse(whoisResult)
40+
if err == nil {
41+
fmt.Printf("\n\tRegistrant: "+result.Registrant.Name)
42+
fmt.Printf("\n\tEmail: "+result.Registrant.Email)
4843

49-
err := cmd.Run()
50-
if err != nil {
51-
os.Stderr.WriteString(err.Error())
52-
}
53-
if bytes.Contains(cmdOutput.Bytes(), []byte("No whois")) {
54-
println("No whois server known for the provided domain name!");
55-
return nil;
44+
fmt.Printf("\n\tDomain Status: "+result.Registrar.DomainStatus)
45+
fmt.Printf("\n\tCreated Date: "+result.Registrar.CreatedDate)
46+
fmt.Printf("\n\tExpiration Date:"+result.Registrar.ExpirationDate)
47+
}else{
48+
fmt.Printf("\n\tNo whois information available for "+domainName+" \n")
5649
}
57-
fmt.Printf("\nDomain Reg:\n")
58-
fmt.Print(string(cmdOutput.Bytes()))
5950

6051
fmt.Printf("\nHTTPS:\n")
6152
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
6253
res, err := http.Get("https://"+domainName)
6354

6455
if err != nil {
65-
fmt.Printf(" Reply: Invalid Response!\n")
56+
fmt.Printf("\tReply: Invalid Response!\n")
6657
}else{
6758
if res.StatusCode >= 200 && res.StatusCode <= 299 {
68-
fmt.Printf(" Reply: Valid [%d]\n", res.StatusCode)
59+
fmt.Printf("\tReply: Valid [%d]\n", res.StatusCode)
6960
} else {
70-
fmt.Printf(" Reply: Invalid [%d]\n", res.StatusCode)
61+
fmt.Printf("\tReply: Invalid [%d]\n", res.StatusCode)
7162
}
7263
//Capture Page Title
7364
htmlBytes, _ := ioutil.ReadAll(res.Body)
7465
htmlStr := string(htmlBytes)
7566
domStart := strings.Index(htmlStr, "<title>") //get title
7667
if domStart == -1 {
77-
fmt.Printf(" No Page Title Found.\n")
68+
fmt.Printf("\tNo Page Title Found.\n")
7869
}else{
7970
domStart += 7 //skips <title>
8071
domEnd := strings.Index(htmlStr, "</title>") //get ending
8172
if domEnd == -1 {
82-
fmt.Printf(" Error in Title.\n")
73+
fmt.Printf("\tError in Title.\n")
8374
}else{
8475
siteTitle := []byte(htmlStr[domStart:domEnd])
85-
fmt.Printf(" Page Title: %s\n", siteTitle)
76+
fmt.Printf("\tPage Title: %s\n", siteTitle)
8677
}
8778
}
8879
}
@@ -92,42 +83,42 @@ func main() {
9283
fmt.Printf("\nHost(s):\n")
9384
ips, err := net.LookupIP(domainName)
9485
if err != nil {
95-
fmt.Printf(" [got errors]\n")
86+
fmt.Printf("[!]\n")
9687
}else if len(ips) == 0 {
9788
fmt.Printf("No host record found.")
9889
}
9990
for _, ip := range ips {
100-
fmt.Printf(" %s\n", ip.String())
91+
fmt.Printf("\t%s\n", ip.String())
10192
}
10293

10394
fmt.Printf("\nNS record(s):\n")
10495
nss, err := net.LookupNS(domainName)
10596
if err != nil {
106-
fmt.Printf(" [got errors]\n")
97+
fmt.Printf("[!]\n")
10798
} else if len(nss) == 0 {
10899
fmt.Printf("No NS records found.")
109100
}
110101
for _, ns := range nss {
111-
fmt.Printf(" %s\n", ns.Host)
102+
fmt.Printf("\t%s\n", ns.Host)
112103
}
113104

114105

115106
fmt.Printf("\nMX record(s):\n")
116107
mxs, err := net.LookupMX(domainName)
117108
if err != nil {
118-
fmt.Printf(" [got errors]\n")
109+
fmt.Printf("[!]\n")
119110
}else if len(mxs) == 0 {
120111
fmt.Printf("No MX records found.")
121112
}
122113
for _, mx := range mxs {
123-
fmt.Printf(" %s %v\n", mx.Host, mx.Pref)
114+
fmt.Printf("\t%s %v\n", mx.Host, mx.Pref)
124115
}
125116

126117

127118
fmt.Printf("\nTXT record(s):\n")
128119
txts, err := net.LookupTXT(domainName)
129120
if err != nil {
130-
fmt.Printf(" [got errors]\n")
121+
fmt.Printf("[!]\n")
131122
}else if len(txts) == 0 {
132123
fmt.Printf("No TXT records found.")
133124
}

0 commit comments

Comments
 (0)