random-ethereum-scanner/index.js

97 lines
2.8 KiB
JavaScript
Raw Normal View History

const Web3 = require("web3")
const ethNetwork = 'https://cloudflare-eth.com'
const ethscan = require('@mycrypto/eth-scan')
const web3 = new Web3(new Web3.providers.HttpProvider(ethNetwork))
const fs = require('fs')
const nodemailer = require("nodemailer")
const express = require("express")
const path = require('path');
const app = express();
const port = process.env.PORT || "8000";
let count = 0
let balancesFound = 0
2022-10-21 22:43:56 +00:00
const transporter = nodemailer.createTransport({
2022-10-21 22:43:56 +00:00
service: 'gmail',
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS
}
})
2022-10-21 22:43:56 +00:00
function main(_count, _balancesFound){
balancesFound = _balancesFound
count = _count
2022-10-21 22:43:56 +00:00
let accounts = []
let x = 0
while(x < 100) {
accounts.push(web3.eth.accounts.create())
count++
x++
}
search(accounts)
2022-10-21 22:43:56 +00:00
}
function search(accounts) {
2022-10-21 22:43:56 +00:00
let addresses = accounts.map((account) => { return account.address })
ethscan.getEtherBalances(web3, addresses).then(balanceMap => {
for (const [key, value] of Object.entries(balanceMap)) {
if(BigInt(value) > 0) {
balancesFound++
2022-10-21 22:43:56 +00:00
message = key + ": " + accounts[addresses.indexOf(key)].privateKey + "\n"
writeToFile('/output/output.txt', message)
transporter.sendMail({
from: '"Random Ethereum Scanner" <foo@example.com>',
to: process.env.EMAIL_TO,
2022-10-21 22:43:56 +00:00
subject: "$$$ We Found Ethereum!",
text: message,
}).catch(emailError)
}
}
main(count, balancesFound)
2022-10-22 12:06:54 +00:00
}).catch((err)=> { emailError(err, true) })
2022-10-21 22:43:56 +00:00
}
2022-10-22 11:56:19 +00:00
function emailError(err, restart = false){
2022-10-22 12:06:54 +00:00
console.log(err)
// transporter.sendMail({
// from: '"Random Ethereum Scanner" <foo@example.com>',
// to: process.env.EMAIL_TO, // Test email address
// subject: "Error detected",
// text: err.toString(),
// }).catch((err)=>{writeToFile('/output/err.txt', err.toString())})
2022-10-22 11:56:19 +00:00
if (restart) {
main(count, balancesFound)
}
2022-10-21 22:43:56 +00:00
}
function writeToFile(filename, message) {
fs.appendFile(filename, message, err => {
if (err) {
console.log(err)
}
})
2022-10-21 22:43:56 +00:00
}
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, '/index.html'))
});
app.get("/stats", (req, res) => {
res.status(200).send({ "count": count,"balancesFound": balancesFound });
});
app.listen(port, () => {
console.log(`Listening to requests on http://localhost:${port}`)
});
2022-10-21 22:43:56 +00:00
transporter.sendMail({
from: '"Random Ethereum Scanner" <foo@example.com>',
to: process.env.EMAIL_TO, // Test email address
subject: "Scanner Started",
text: "Random Ethereum Scanner Started Successfully",
}).catch((err)=>{writeToFile('/output/err.txt', err.toString())})
main(count, balancesFound)