Skip to content

Instantly share code, notes, and snippets.

@achillean
Last active May 17, 2021 12:44
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save achillean/8367958 to your computer and use it in GitHub Desktop.
Save achillean/8367958 to your computer and use it in GitHub Desktop.
Shodan macros for Google Spreadsheets. To use this go to Tools -> Script Editor, then copy/ paste the code. In the spreadsheet you can then do: =SHODAN_COUNT("cisco-ios") =SHODAN_FACET_KEYS("cisco-ios", "org") =SHODAN_FACET_VALUES("cisco-ios", "org")
var API_KEY = 'YOUR API KEY';
/**
* Search the Shodan database using the given query. Returns the number of matches.
*/
function SHODAN_COUNT(query) {
var url = 'https://api.shodan.io/shodan/host/count?key=' + API_KEY + '&query=' + query;
var response = UrlFetchApp.fetch(url);
var data = Utilities.jsonParse(response.getContentText());
return data.total;
};
/**
* Return the names of the facet values for a given search. Optionally, you can also provide a total number of
* facet results that should be returned. Use this method alongside SHODAN_FACET_VALUES to get the corresponding
* values for a facet name. Most filters can be used as facets.
*/
function SHODAN_FACET_KEYS(query, facet, count) {
if (!count) {
count = 10;
}
var url = 'https://api.shodan.io/shodan/host/count?key=' + API_KEY + '&query=' + query + '&facets=' + facet + ':' + count;
var response = UrlFetchApp.fetch(url);
var data = Utilities.jsonParse(response.getContentText());
var values = [];
for (var i = 0; i < data.facets[facet].length; i++) {
values.push(data.facets[facet][i].value);
}
return values;
};
/**
* Return the values of the facet values for a given search. Optionally, you can also provide a total number of
* facet results that should be returned. Use this method alongside SHODAN_FACET_KEYS to get the corresponding
* names for a facet value. Most filters can be used as facets.
*/
function SHODAN_FACET_VALUES(query, facet, count) {
if (!count) {
count = 10;
}
var url = 'https://api.shodan.io/shodan/host/count?key=' + API_KEY + '&query=' + query + '&facets=' + facet + ':' + count;
var response = UrlFetchApp.fetch(url);
var data = Utilities.jsonParse(response.getContentText());
var values = [];
for (var i = 0; i < data.facets[facet].length; i++) {
values.push(data.facets[facet][i].count);
}
return values;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment