Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alpkeskin
GitHub Repository: alpkeskin/mosint
Path: blob/master/v3/pkg/services/hunter/hunter.go
689 views
1
/*
2
Copyright © 2023 github.com/alpkeskin
3
*/
4
package hunter
5
6
import (
7
"encoding/json"
8
"fmt"
9
"io"
10
"net/http"
11
"strings"
12
13
"github.com/alpkeskin/mosint/v3/internal/config"
14
"github.com/alpkeskin/mosint/v3/internal/spinner"
15
"github.com/fatih/color"
16
)
17
18
type Hunter struct {
19
Response HunterResponse
20
}
21
22
type HunterResponse struct {
23
Data struct {
24
Domain string `json:"domain"`
25
Disposable bool `json:"disposable"`
26
Webmail bool `json:"webmail"`
27
AcceptAll bool `json:"accept_all"`
28
Pattern string `json:"pattern"`
29
Organization string `json:"organization"`
30
Country string `json:"country"`
31
State interface{} `json:"state"`
32
Emails []struct {
33
Value string `json:"value"`
34
Type string `json:"type"`
35
Confidence int `json:"confidence"`
36
Sources []struct {
37
Domain string `json:"domain"`
38
URI string `json:"uri"`
39
ExtractedOn string `json:"extracted_on"`
40
LastSeenOn string `json:"last_seen_on"`
41
StillOnPage bool `json:"still_on_page"`
42
} `json:"sources"`
43
FirstName string `json:"first_name"`
44
LastName string `json:"last_name"`
45
Position string `json:"position"`
46
Seniority string `json:"seniority"`
47
Department string `json:"department"`
48
Linkedin interface{} `json:"linkedin"`
49
Twitter interface{} `json:"twitter"`
50
PhoneNumber interface{} `json:"phone_number"`
51
Verification struct {
52
Date string `json:"date"`
53
Status string `json:"status"`
54
} `json:"verification"`
55
} `json:"emails"`
56
LinkedDomains []interface{} `json:"linked_domains"`
57
} `json:"data"`
58
Meta struct {
59
Results int `json:"results"`
60
Limit int `json:"limit"`
61
Offset int `json:"offset"`
62
Params struct {
63
Domain string `json:"domain"`
64
Company interface{} `json:"company"`
65
Type interface{} `json:"type"`
66
Seniority interface{} `json:"seniority"`
67
Department interface{} `json:"department"`
68
} `json:"params"`
69
} `json:"meta"`
70
}
71
72
func New() *Hunter {
73
return &Hunter{}
74
}
75
76
func (h *Hunter) Lookup(email string) {
77
spinner := spinner.New("Related Emails Searching")
78
spinner.Start()
79
80
key := config.Cfg.Services.HunterApiKey
81
if strings.EqualFold(key, "") {
82
spinner.StopFail()
83
spinner.SetMessage("Hunter Api Key is empty")
84
return
85
}
86
87
domain := email[strings.IndexByte(email, '@')+1:]
88
url := fmt.Sprintf("https://api.hunter.io/v2/domain-search?domain=%s&api_key=%s", domain, key)
89
req, err := http.NewRequest("GET", url, nil)
90
91
if err != nil {
92
spinner.StopFail()
93
spinner.SetMessage(err.Error())
94
return
95
}
96
97
req.Header.Set("User-Agent", "mosint")
98
client := &http.Client{}
99
resp, err := client.Do(req)
100
101
if err != nil {
102
spinner.StopFail()
103
spinner.SetMessage(err.Error())
104
return
105
}
106
107
body, err := io.ReadAll(resp.Body)
108
109
if err != nil {
110
spinner.StopFail()
111
spinner.SetMessage(err.Error())
112
return
113
}
114
115
defer resp.Body.Close()
116
var response HunterResponse
117
json.Unmarshal(body, &response)
118
h.Response = response
119
spinner.Stop()
120
}
121
122
func (h *Hunter) Print() {
123
key := config.Cfg.Services.HunterApiKey
124
if strings.EqualFold(key, "") {
125
return
126
}
127
128
fmt.Println("[*] Hunter.io Search Results")
129
130
fmt.Println(color.GreenString("[+]"), "Disposable:", h.Response.Data.Disposable)
131
fmt.Println(color.GreenString("[+]"), "Webmail:", h.Response.Data.Webmail)
132
fmt.Println(color.GreenString("[+]"), "AcceptAll:", h.Response.Data.AcceptAll)
133
fmt.Println(color.GreenString("[+]"), "Pattern:", h.Response.Data.Pattern)
134
fmt.Println(color.GreenString("[+]"), "Organization:", h.Response.Data.Organization)
135
fmt.Println(color.GreenString("[+]"), "Country:", h.Response.Data.Country)
136
137
fmt.Println("[*] Related Emails:")
138
if len(h.Response.Data.Emails) == 0 {
139
fmt.Println(color.RedString("[!]"), "No related emails found")
140
return
141
}
142
for _, v := range h.Response.Data.Emails {
143
fmt.Println(color.GreenString("[+]"), v.Value)
144
}
145
}
146
147