Added Ruby & Added support for multiple protocols
This commit is contained in:
parent
6c9e377183
commit
436f9d80d3
4 changed files with 170 additions and 7 deletions
76
Node.js/index.js
Normal file
76
Node.js/index.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
const https = require('https')
|
||||
const http = require('http')
|
||||
const fs = require('fs')
|
||||
|
||||
async function main_loop() {
|
||||
for (let i = 0; i < times; i++) {
|
||||
const url = await url_generator(domains, mode, log)
|
||||
try {
|
||||
const response = await fetch(url)
|
||||
console.log(`${url} exists!`)
|
||||
fs.appendFile("JS_report.txt", "\n" + url + " | STATUS_CODE: " + String(response.statusCode), function(err) {if (err) throw err})
|
||||
}
|
||||
catch(e) {
|
||||
if (e.errno != 'ENOTFOUND') {
|
||||
console.log(`${url} exists!`)
|
||||
fs.appendFile("JS_report.txt", "\n" + url + " | ERROR_CODE: " + e.errno, function(err) {if (err) throw err})
|
||||
}
|
||||
}
|
||||
}
|
||||
fs.appendFile("JS_report.txt", "\n---\n", function(err) {if (err) throw err})
|
||||
console.log('\nFinished at ' + String(new Date().getHours()) + 'h' + String(new Date().getMinutes()) + 'm')
|
||||
}
|
||||
|
||||
function url_generator(domains, mode, log) {
|
||||
let result = mode[Math.round(Math.random() * (mode.length - 1))] + "://"
|
||||
const characters = "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||
const url_length = Math.floor(Math.random() * (30 - 2) + 2)
|
||||
for (let i = 0; i < url_length; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * characters.length))
|
||||
}
|
||||
result += domains[Math.floor(Math.random() * domains.length)]
|
||||
if (log) console.log(result)
|
||||
return result
|
||||
}
|
||||
|
||||
function fetch(url, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!url) return reject(new Error('URL was not provided'))
|
||||
|
||||
const { body, method = 'GET', ...restOptions } = options
|
||||
const client = url.startsWith('https') ? https : http
|
||||
const request = client.request(url, { method, ...restOptions }, (res) => {
|
||||
let chunks = ''
|
||||
res.setEncoding('utf8')
|
||||
res.on('data', (chunk) => {
|
||||
chunks += chunk
|
||||
})
|
||||
res.on('end', () => {
|
||||
resolve({ statusCode: res.statusCode, body: chunks })
|
||||
})
|
||||
})
|
||||
request.on('error', (err) => {
|
||||
reject(err)
|
||||
})
|
||||
if (body) {
|
||||
request.setHeader('Content-Length', body.length)
|
||||
request.write(body)
|
||||
}
|
||||
request.end()
|
||||
})
|
||||
}
|
||||
|
||||
const times = process.argv.indexOf('-t') > -1 ? Math.round(Number(process.argv[process.argv.indexOf('-t') + 1])) : 3000
|
||||
if (isNaN(times)) return console.error("-t argument expected a number!")
|
||||
const domains = process.argv.indexOf('-d') > -1 ? process.argv[process.argv.indexOf('-d') + 1].split(',') : ['.com', '.net', '.edu', '.gov', '.cn', '.org']
|
||||
const mode = process.argv.indexOf('-m') > -1 ? process.argv[process.argv.indexOf('-m') + 1].split(',') : ['http']
|
||||
const log = process.argv.indexOf('-l') > -1
|
||||
|
||||
process.stdout.write(`\nI am going to look for images through ${times} random URLs with the following domains: `)
|
||||
console.log(domains)
|
||||
process.stdout.write("These URLs will use the following protocols: ")
|
||||
console.log(mode)
|
||||
console.log('Started at ' + String(new Date().getHours()) + 'h' + String(new Date().getMinutes()) + 'm\n')
|
||||
|
||||
fs.appendFile("JS_report.txt", "---", function(err) {if (err) throw err})
|
||||
main_loop()
|
Loading…
Add table
Add a link
Reference in a new issue