Skip to content

Commit

Permalink
resolving issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
MilindPurswani committed Aug 28, 2020
1 parent c624213 commit a0b32ad
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@

# Dependency directories (remove the comment below to include it)
# vendor/
main
92 changes: 74 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/url"
"os"
"strconv"
"strings"
)

// ResponseStruct returns response_struct
Expand Down Expand Up @@ -40,9 +41,46 @@ type SearchResult struct {
RegistrarName string `json:"registrar_name"`
}

func getResult(page int, cn string, apikey string) int {
var whoxyURL = "http://api.whoxy.com/?key=" + apikey + "&reverse=whois&mode=micro&company=" + url.QueryEscape(cn) + "&page=" + strconv.Itoa(page)
// fmt.Println(whoxyURL2)
// KeywordStruct results more than 50,000 domains
type KeywordStruct struct {
Status int `json:"status"`
APIQuery string `json:"api_query"`
SearchIdentifier2 SearchIdentifier2 `json:"search_identifier"`
TotalResults int `json:"total_results"`
TotalPages int `json:"total_pages"`
CurrentPage int `json:"current_page"`
DomainNames string `json:"domain_names"`
APIExecutionTime float64 `json:"api_execution_time"`
}

// SearchIdentifier2 is of type SearchIdentifier2
type SearchIdentifier2 struct {
Keyword string `json:"keyword"`
}

func apiGenerator(cn string, name string, email string, keyword string) (string, string) {
apikey, present := os.LookupEnv("WHOXY_API_KEY")
mode := "micro"
if present != true {
log.Fatal("Are you sure you've set 'WHOXY_API_KEY' environmental variable?")
}
var whoxyURL = "http://api.whoxy.com/?key=" + apikey + "&reverse=whois"
if len(cn) > 0 {
whoxyURL = whoxyURL + "&mode=micro&company=" + url.QueryEscape(cn)
} else if len(name) > 0 {
whoxyURL = whoxyURL + "&mode=micro&name=" + url.QueryEscape(name)
} else if len(email) > 0 {
whoxyURL = whoxyURL + "&mode=micro&email=" + url.QueryEscape(email)
} else if len(keyword) > 0 {
whoxyURL = whoxyURL + "&mode=domains&keyword=" + url.QueryEscape(keyword)
mode = "domain"
}
return whoxyURL, mode
}

func getResult(page int, url string, mode string) int {

var whoxyURL = url + "&page=" + strconv.Itoa(page)
// var whoxyURL = "https://www.whoxy.com/sample/reverseWhoisMicro.json"
resp, err := http.Get(whoxyURL)
if err != nil {
Expand All @@ -52,35 +90,53 @@ func getResult(page int, cn string, apikey string) int {
if err != nil {
log.Fatal(err)
}
respHandler := ResponseStruct{}
respString := string(respData)
err = json.Unmarshal([]byte(respString), &respHandler)
if err != nil {
log.Fatal(err)
}
for j := 0; j < len(respHandler.SearchResult); j++ {
fmt.Println(respHandler.SearchResult[j].DomainName)
if mode == "micro" {
respHandler := ResponseStruct{}
respString := string(respData)
err = json.Unmarshal([]byte(respString), &respHandler)
if err != nil {
log.Fatal(err)
}
for j := 0; j < len(respHandler.SearchResult); j++ {
fmt.Println(respHandler.SearchResult[j].DomainName)
}
return respHandler.TotalPages
} else {
respHandler := KeywordStruct{}
respString := string(respData)
err = json.Unmarshal([]byte(respString), &respHandler)
if err != nil {
log.Fatal(err)
}
d := strings.Split(respHandler.DomainNames, ",")
for j := 0; j < len(d); j++ {
fmt.Println(d[j])
}
return respHandler.TotalPages
}
return respHandler.TotalPages
}

func main() {
var cn string
flag.StringVar(&cn, "company-name", "", "Company Name for which you need to get all the assets from whoxy")
var name string
flag.StringVar(&name, "name", "", "Domain Name for which you need to get all the assets from whoxy")
var email string
flag.StringVar(&email, "email", "", "Email address for which you need to get all the assets from whoxy")
var keyword string
flag.StringVar(&keyword, "keyword", "", "Keyword for which you need to get all the assets from whoxy. Returns much more results but high chances of false positives. Get 50,000 results in one request.")
var rCount int
flag.IntVar(&rCount, "result-count", -1, "The count of results that you need to fetch from the API. Keep in mind that 1 request will give 2500 domains only. So, if you want to fetch 10,000 results, the tool will make 4 requests. Make sure you have sufficient credits available.")
flag.Parse()
if flag.NArg() > 0 {
log.Fatal("Kindly check the docs whoxy -h for usage")
}
apikey, present := os.LookupEnv("WHOXY_API_KEY")
if present != true {
log.Fatal("Are you sure you've set 'WHOXY_API_KEY' environmental variable?")
}
pageCount := getResult(rCount, cn, apikey)

whoxyURL, mode := apiGenerator(cn, name, email, keyword)
pageCount := getResult(rCount, whoxyURL, mode)
if pageCount > 1 {
for i := 1; i <= pageCount; i++ {
_ = getResult(i, cn, apikey)
_ = getResult(i, whoxyURL, mode)
}
}

Expand Down

0 comments on commit a0b32ad

Please sign in to comment.