Skip to content

Implementations

Michael - Blurpesec edited this page Jan 31, 2019 · 10 revisions

Example Custom Implementations:

You can also see these in the repo here: https://github.com/hahnmichaelf/urlscan-api/tree/master/examples


Submit and get results
const urlscan = require('urlscan-api')

// Submits a domain and then queries to get the result of the scan when it is complete.
const APIKEY = your_api_key_here
let domaintosubmit = 'https://mycrypto.com'
new urlscan().submit(APIKEY, domaintosubmit).then( function( submitoutput ) {
    get_result(submitoutput.uuid)
} )

// console.logs the output JSON from urlscan.result( uuid)
get_result = (uuid) => {
    var resultwait = setInterval(function() {
        new urlscan().result(uuid).then( function( resultoutput ) {
            if (resultoutput.statusCode != 404) {
                console.log(JSON.stringify(resultoutput, null, 2))
                clearInterval(resultwait)
            }
        } )
    }, 10 * 1000) // re-check every 10 second
};
Submit and download screenshot
const urlscan = require('urlscan-api')
const config = require('../config.js')
const APIKEY = config.APIKEY
const filename = 'mycrypto.png'

// Submits a domain and then downloads the screenshot when the scan is complete.
let domaintosubmit = 'https://mycrypto.com'
new urlscan().submit(APIKEY, domaintosubmit).then( function( submitoutput ) {
    get_result(submitoutput.uuid)
} )


get_result = (uuid) => {
    var resultwait = setInterval(function() {
        new urlscan().result(uuid).then( function( resultoutput ) {
            if (resultoutput.statusCode != 404) {
                downloadscreenshot(uuid, filename)
                clearInterval(resultwait)
            }
        } )
    }, 10 * 1000) // re-check every 10 second
};

downloadscreenshot = (uuid, filename) => {
    new urlscan().downloadscreenshot(uuid, filename).then( function( downloadstatus ) {
        console.log(JSON.stringify(downloadstatus, null, 2))
    } )
}
Submit and download DOM
const urlscan = require('urlscan-api')
const config = require('../config.js')
const APIKEY = config.APIKEY
const filename = 'mycrypto.txt'

// Submits a domain and then downloads the DOM when the scan is complete.
let domaintosubmit = 'https://mycrypto.com'
new urlscan().submit(APIKEY, domaintosubmit).then( function( submitoutput ) {
    get_result(submitoutput.uuid)
} )


get_result = (uuid) => {
    var resultwait = setInterval(function() {
        new urlscan().result(uuid).then( function( resultoutput ) {
            if (resultoutput.statusCode != 404) {
                downloaddom(uuid, filename)
                clearInterval(resultwait)
            }
        } )
    }, 10 * 1000) // re-check every 10 second
};

downloaddom = (uuid, filename) => {
    new urlscan().downloaddom(uuid, filename).then( function( downloadstatus ) {
        console.log(JSON.stringify(downloadstatus, null, 2))
    } )
}
Search and get most recent result
const urlscan = require('urlscan-api')

// Submits a domain and then queries to get the result of the scan when it is complete.
const APIKEY = your_api_key_here
let domaintosearch = 'mycrypto.com'
new urlscan().searchdomain(domaintosearch).then( function( searchoutput ) {
    get_result(searchoutput.results[0]._id)
} )

// console.logs the result associated with the most-recent task when searching for a domain.
get_result = (uuid) => {
    new urlscan().result(uuid).then( function( resultoutput ) {
        if (resultoutput.statusCode != 404) {
            console.log(JSON.stringify(resultoutput, null, 2))
        }
    } )
};