From e60d1a5c4f72196480e3cf1b98af1b53b00b998b Mon Sep 17 00:00:00 2001 From: sundowndev Date: Sat, 12 Sep 2020 18:34:23 +0200 Subject: [PATCH 1/2] feat: add missing dorks in google search fixes #14 --- googlesearch/googlesearch.go | 66 +++++++++++++++++++++++++------ googlesearch/googlesearch_test.go | 60 ++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 12 deletions(-) diff --git a/googlesearch/googlesearch.go b/googlesearch/googlesearch.go index a6b1af4..37622bc 100644 --- a/googlesearch/googlesearch.go +++ b/googlesearch/googlesearch.go @@ -6,18 +6,24 @@ import ( ) const ( - searchURL = "https://www.google.com/search" - siteTag = "site:" - urlTag = "inurl:" - filetypeTag = "filetype:" - cacheTag = "cache:" - relatedTag = "related:" - extTag = "ext:" - excludeTag = "-" - intitleTag = "intitle:" - intextTag = "intext:" - operatorOr = "|" - operatorAnd = "+" + searchURL = "https://www.google.com/search" + siteTag = "site:" + urlTag = "inurl:" + filetypeTag = "filetype:" + cacheTag = "cache:" + relatedTag = "related:" + extTag = "ext:" + excludeTag = "-" + intitleTag = "intitle:" + intextTag = "intext:" + operatorOr = "|" + operatorAnd = "+" + bookTag = "book:" + ipTag = "ip:" + mapsTag = "maps:" + allintextTag = "allintext:" + infoTag = "info:" + inanchorTag = "inanchor:" ) // GoogleSearch is the Google search implementation for Dorkgen @@ -139,3 +145,39 @@ func (e *GoogleSearch) Plain(value string) *GoogleSearch { e.tags = append(e.tags, value) return e } + +// Book searches for book titles related to keywords. +func (e *GoogleSearch) Book(keyword string) *GoogleSearch { + e.tags = append(e.tags, e.join(bookTag, keyword, true)) + return e +} + +// IP finds sites hosted by a specific ip address. +func (e *GoogleSearch) IP(address string) *GoogleSearch { + e.tags = append(e.tags, e.join(ipTag, address, false)) + return e +} + +// Maps searches for maps related to keywords. +func (e *GoogleSearch) Maps(location string) *GoogleSearch { + e.tags = append(e.tags, e.join(mapsTag, location, false)) + return e +} + +// AllInText searches text of page. +func (e *GoogleSearch) AllInText(text string) *GoogleSearch { + e.tags = append(e.tags, e.join(allintextTag, text, true)) + return e +} + +// Info presents some information that Google has about a web page, including similar pages, the cached version of the page, and sites linking to the page. +func (e *GoogleSearch) Info(url string) *GoogleSearch { + e.tags = append(e.tags, e.join(infoTag, url, true)) + return e +} + +// InAnchor search link anchor text. +func (e *GoogleSearch) InAnchor(text string) *GoogleSearch { + e.tags = append(e.tags, e.join(inanchorTag, text, true)) + return e +} diff --git a/googlesearch/googlesearch_test.go b/googlesearch/googlesearch_test.go index d2f9142..1dc0716 100644 --- a/googlesearch/googlesearch_test.go +++ b/googlesearch/googlesearch_test.go @@ -175,4 +175,64 @@ func TestInit(t *testing.T) { "q": []string{"site:linkedin.com (intext:\"1\" | intext:\"2\") intitle:\"jordan\""}, }, result, "they should be equal") }) + + t.Run("should use book tag", func(t *testing.T) { + dork = googlesearch.New() + + result := dork. + Book("test"). + String() + + assert.Equal("book:\"test\"", result, "they should be equal") + }) + + t.Run("should use ip tag", func(t *testing.T) { + dork = googlesearch.New() + + result := dork. + IP("172.217.19.238"). + String() + + assert.Equal("ip:172.217.19.238", result, "they should be equal") + }) + + t.Run("should use maps tag", func(t *testing.T) { + dork = googlesearch.New() + + result := dork. + Maps("france"). + String() + + assert.Equal("maps:france", result, "they should be equal") + }) + + t.Run("should use allintext tag", func(t *testing.T) { + dork = googlesearch.New() + + result := dork. + AllInText("test"). + String() + + assert.Equal("allintext:\"test\"", result, "they should be equal") + }) + + t.Run("should use info tag", func(t *testing.T) { + dork = googlesearch.New() + + result := dork. + Info("https://google.com/"). + String() + + assert.Equal("info:\"https://google.com/\"", result, "they should be equal") + }) + + t.Run("should use inanchor tag", func(t *testing.T) { + dork = googlesearch.New() + + result := dork. + InAnchor("test"). + String() + + assert.Equal("inanchor:\"test\"", result, "they should be equal") + }) } From 313788473b98efc26e84d2e14d386c3f9fcf0484 Mon Sep 17 00:00:00 2001 From: sundowndev Date: Sat, 12 Sep 2020 18:46:53 +0200 Subject: [PATCH 2/2] refactor: remove ip tag in google search --- googlesearch/googlesearch.go | 6 ------ googlesearch/googlesearch_test.go | 10 ---------- 2 files changed, 16 deletions(-) diff --git a/googlesearch/googlesearch.go b/googlesearch/googlesearch.go index 37622bc..3d47bf0 100644 --- a/googlesearch/googlesearch.go +++ b/googlesearch/googlesearch.go @@ -152,12 +152,6 @@ func (e *GoogleSearch) Book(keyword string) *GoogleSearch { return e } -// IP finds sites hosted by a specific ip address. -func (e *GoogleSearch) IP(address string) *GoogleSearch { - e.tags = append(e.tags, e.join(ipTag, address, false)) - return e -} - // Maps searches for maps related to keywords. func (e *GoogleSearch) Maps(location string) *GoogleSearch { e.tags = append(e.tags, e.join(mapsTag, location, false)) diff --git a/googlesearch/googlesearch_test.go b/googlesearch/googlesearch_test.go index 1dc0716..7a5c4df 100644 --- a/googlesearch/googlesearch_test.go +++ b/googlesearch/googlesearch_test.go @@ -186,16 +186,6 @@ func TestInit(t *testing.T) { assert.Equal("book:\"test\"", result, "they should be equal") }) - t.Run("should use ip tag", func(t *testing.T) { - dork = googlesearch.New() - - result := dork. - IP("172.217.19.238"). - String() - - assert.Equal("ip:172.217.19.238", result, "they should be equal") - }) - t.Run("should use maps tag", func(t *testing.T) { dork = googlesearch.New()