-
-
Save IAmStoxe/13a995a05a628cc61d5fed35659babe7 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")
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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