Skip to content

Instantly share code, notes, and snippets.

@dorp007
Forked from achillean/shodan-google-spreadsheet.js
Last active November 14, 2023 18:24
Show Gist options
  • Save dorp007/a0d716633f04a529abcc8a52f4e4c42e to your computer and use it in GitHub Desktop.
Save dorp007/a0d716633f04a529abcc8a52f4e4c42e 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