Skip to content

Instantly share code, notes, and snippets.

@RomanHargrave
Created June 27, 2020 04:46
Show Gist options
  • Select an option

  • Save RomanHargrave/751af11bb363da5d0d640bb5a99d77fd to your computer and use it in GitHub Desktop.

Select an option

Save RomanHargrave/751af11bb363da5d0d640bb5a99d77fd to your computer and use it in GitHub Desktop.
Userscript to add copy link next to search result ip on shodan
// ==UserScript==
// @name Shodan quick copy IP
// @namespace Violentmonkey Scripts
// @match https://www.shodan.io/search
// @grant none
// @version 1.0
// @author Roman Hargrave <[email protected]>
// @description 6/26/2020, 3:32:30 PM
// ==/UserScript==
window.addEventListener("load", function() {
(function(document, navigator, console) {
function queryFirst(xpath, base) {
return document.evaluate(xpath, base, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
function queryAll(xpath, base, callback) {
const result = document.evaluate(xpath, base, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE);
for(var index = 0; index < result.snapshotLength; ++index) {
callback(result.snapshotItem(index));
}
}
function extractComponents(resultElement) {
const ipDiv = queryFirst('./div[contains(@class, "ip")]', resultElement);
const ipAnchor = queryFirst('./a[starts-with(@href, "/host/")]', ipDiv);
return {
div: ipDiv,
address: ipAnchor.innerText
};
}
function appendCopyButton(ipDiv, address) {
const button = document.createElement('a');
button.addEventListener('click', function(event) {
navigator.clipboard.writeText(address);
event.preventDefault();
});
button.style = "font-size: 10pt;";
button.innerText = "(copy)";
ipDiv.append(button);
}
queryAll('//div[@class="search-result"]', document, function(searchResult) {
const props = extractComponents(searchResult);
appendCopyButton(props.div, props.address);
});
})(document, navigator, console)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment