Tutorials

Tutorials

Searching the Web with GPAL.GoogleDorking

GPAL.GoogleDorking wraps the Google Custom Search API behind a fluent query builder. This tutorial sets up credentials, builds a simple search, then layers on advanced operators like site restriction, file type, exact phrase, and date restriction, all returning results as a familiar IGPALGrid.

Complete Program

Here's the whole workflow, start to finish. Each piece is broken down and explained below.

using GenerallyPositive;

using static GenerallyPositive.Enums;

GPAL.WithPublishToConsole();

string apiKey = "YOUR_API_KEY";

string engineId = "YOUR_SEARCH_ENGINE_ID";

IGoogleDorking dorkClient = GPAL.GoogleDorkingFor(apiKey, engineId);

IGPALGrid<string> results;

// Simple search

dorkClient

.SearchFor("dead mike")

.GetResults(out results);

PrintResults(results);

// Full query with site, file type, and date restrictions

dorkClient

.WithSite("example.com")

.WithFileType(FileType.Pdf)

.WithInTitle("report")

.WithExcludeTerm("draft")

.WithResultsPerPageUpTo10(10)

.WithDateRestriction(DateRestriction.PastYear)

.WithSortBy(SortOption.Date)

.SearchForExactPhrase("financial report")

.GetResults(out results);

PrintResults(results);

void PrintResults(IGPALGrid<string> grid)

{

if (0 < grid.Count())

{

foreach (var row in grid)

Console.WriteLine($"Result: Title={row[0]}, Link={row[1]}, Snippet={row[2]}");

}

else

{

Console.WriteLine("No results returned.");

}

}

Create the GoogleDorking Client

GPAL.GoogleDorkingFor takes a Google API key and a Programmable Search Engine ID and hands you back an IGoogleDorking client. Once created, the client is reusable across as many searches as you need - each call to SearchFor and GetResults runs independently against the same configuration.

string apiKey = "YOUR_API_KEY";

string engineId = "YOUR_SEARCH_ENGINE_ID";

IGoogleDorking dorkClient = GPAL.GoogleDorkingFor(apiKey, engineId);

TIP

The API key comes from the Google Cloud Console under Credentials, and the search engine ID (cx=) comes from the Programmable Search Engine control panel. Both are required before any search will return results.

A Simple Search

The minimum workflow is SearchFor followed by GetResults. GetResults fills an IGPALGrid<string> where each row has three columns: title, link, and snippet - the same shape you'd get back from any GPAL grid-producing call.

IGPALGrid<string> results;

dorkClient

.SearchFor("dead mike")

.GetResults(out results);

Layering on Dork Operators

Every Google dorking operator has a corresponding With* method: WithSite restricts to a domain, WithFileType filters by file extension, WithInTitle and WithInUrl search specific parts of a page, WithExcludeTerm removes unwanted terms, and SearchForExactPhrase wraps the term in quotes. Chain as many as you need before calling GetResults.

dorkClient

.WithSite("example.com")

.WithFileType(FileType.Pdf)

.WithInTitle("report")

.WithExcludeTerm("draft")

.WithResultsPerPageUpTo10(10)

.WithDateRestriction(DateRestriction.PastYear)

.WithSortBy(SortOption.Date)

.SearchForExactPhrase("financial report")

.GetResults(out results);

WARNING

WithResultsPerPageUpTo10 only accepts 1-10. Passing an out-of-range value (or an empty search term) doesn't throw - GetResults simply returns an empty grid, so check Count() before assuming a search worked.

Date Restrictions

WithDateRestriction takes a DateRestriction enum value - PastDay, PastWeek, PastMonth, PastYear - or DateRestriction.Custom with a number of months for anything else. This narrows results to content indexed within that window.

dorkClient

.WithDateRestriction(DateRestriction.Custom, 6)

.SearchFor("test")

.GetResults(out results);

// or one of the presets

dorkClient

.WithDateRestriction(DateRestriction.PastWeek)

.SearchFor("test")

.GetResults(out results);