Created
July 6, 2017 17:56
-
-
Save tobius/3f47f42648eceebbf72a455814b232c3 to your computer and use it in GitHub Desktop.
Find URLs inside SQL Dumps
This file contains hidden or 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
/** | |
* [~] npm install chalk lodash | |
* [~] node thisfile.js yourfile.sql | |
*/ | |
var _ = require('lodash'); | |
var chalk = require('chalk'); | |
var fs = require('fs'); | |
var path = process.argv.length > 1 ? process.argv[process.argv.length - 1] : null; | |
if (!path){ | |
console.log(chalk.red('no arguments found')); | |
process.exit(); | |
} | |
console.info(chalk.blue('SCANNING ' + path)); | |
var regex = /["'](((http|https|ftp):\/\/([\w-\d]+\.)+[\w-\d]+){0,1}(\/[\w~,;\-\.\/?%&+#=]*))["']/gmi; | |
var contents = fs.readFileSync(path, 'utf8'); | |
var matches = contents.match(regex); | |
var urls = _.map(matches, function(url){ | |
return url.replace(/^['"]([^'"]+)['"]$/, '$1'); | |
}); | |
var uniqueUrls = _.uniq(urls); | |
console.info(chalk.blue('FOUND ' + urls.length + ' TOTAL URLs')); | |
console.info(chalk.blue('FOUND ' + uniqueUrls.length + ' UNIQUE URLs')); | |
for (var i in uniqueUrls){ | |
console.log(chalk.white(uniqueUrls[i])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment