Skip to content

Instantly share code, notes, and snippets.

@daragao
Created June 7, 2017 09:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daragao/ce2a506d3d272ea31319b445da54dd74 to your computer and use it in GitHub Desktop.
Save daragao/ce2a506d3d272ea31319b445da54dd74 to your computer and use it in GitHub Desktop.
(Useless crazy :D ) Bash script that keeps generating keys and saves the key if that Ethereum account has ether
#!/bin/bash
COUNTER=0
trap '{ echo "Hey, you pressed Ctrl-C. Loop Counter: $COUNTER Time to quit." ; exit 1; }' INT
#./go-ethereum/build/bin/geth --bootnodes enode://f4642fa65af50cfdea8fa7414a5def7bb7991478b768e296f5e4a54e8b995de102e0ceae2e826f293c481b5325f89be6d207b003382e18a8ecba66fbaf6416c0@33.4.2.1:30303 --rpc
#Libs used for keccak-256sum
#https://github.com/maandree/libkeccak.git
#https://github.com/maandree/argparser.git
#https://github.com/maandree/sha3sum.git
while true
do
# Generate the private and public keys
KEY="$(openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout 2> /dev/null)"
#echo "$KEY"
# Extract the public key and remove the EC prefix 0x04
PUB="$(echo "$KEY" | grep pub -A 5 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^04//')"
#echo "Public key:" $PUB
# Extract the private key and remove the leading zero byte
PRIV="$(echo "$KEY" | grep priv -A 3 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^00//')"
#echo "Private key:" $PRIV
# Generate the hash and take the address part
ADDRESS="$(echo "$PUB" | keccak-256sum -x -l | tr -d ' -' | tail -c 41)"
#echo "Address:" $ADDRESS
# (Optional) import the private key to geth
#geth account import priv
#curl -s https://api.blockcypher.com/v1/eth/main/addrs/$ADDRESS | jq .balance
HEX_BALANCE="$(curl --silent -X POST --data\
'{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x'$ADDRESS'", "latest"],"id":1}' \
localhost:8545 | jq .result | sed 's/"0x\(.\+\)"/\U\1/')"
if [ $HEX_BALANCE != "0" ]; then
DEC_BALANCE="$(echo 'ibase=16;obase=A;'$HEX_BALANCE | bc)"
#echo "$KEY"
echo "-----------------------------------------------"
echo "FOUND ONE!!!!"
echo "Public key:" $PUB
echo "Private key:" $PRIV
echo "Address:" $ADDRESS
echo "Balance: " $DEC_BALANCE "wei"
echo "-----------------------------------------------"
DATA_FOUND_STR="Public key:$PUB\nPrivate key:$PRIV\nAddress: $ADDRESS\nBalance: $DEC_BALANCE wei\n"
echo -e "$DATA_FOUND_STR" >> luckyGuess.txt
fi
let COUNTER=COUNTER+1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment