Last active
May 30, 2023 16:31
-
-
Save xero/a73fc5eaf1064a980e8fc034181fc08a to your computer and use it in GitHub Desktop.
aws ip miner
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
#!/bin/bash | |
# interactive aws elastic ip miner tool, get a cool aws ip! | |
# usage: AWS_PROFILE=dev AWS_REGION=us-west-1 ./getip | |
# CC0 xero | https://x-e.ro | https://github.com/xero | |
declare -g region='us-east-2' tmp='' | |
tmp="$(mktemp /tmp/getip.XXXXXXXXXX)" || { echo "failed creating temp file"; exit 1; } | |
[ -z "$AWS_REGION" ] || region="$AWS_REGION" | |
function requirements() { | |
for bin in "$@"; do | |
builtin type -P "$bin" &> /dev/null || { | |
echo >&2 "'$bin' dependancy required"; exit 1 | |
} | |
done | |
} | |
function getnewip() { | |
r=$(aws ec2 allocate-address --domain vpc --region "$region") && | |
i=$(jq -r '.PublicIp'<<<$r) && | |
a=$(jq -r '.AllocationId'<<<$r) && | |
echo "$i:$a" > $tmp | |
} | |
function discardip() { | |
aws ec2 release-address --allocation-id $1 --region "$region" & | |
} | |
function main() { | |
whiptail --title "aws elastic ip miner" --yesno "generate a new ip?" 8 78 || exit 0 | |
truncate -s 0 $tmp | |
getnewip & | |
{ | |
i=0 | |
while [ ! -s "$tmp" ]; do | |
echo "$i" | |
((i=i+25)) | |
sleep 0.25 | |
[ "$i" -gt 100 ] && i=100 | |
done | |
echo 100 | |
} | whiptail --title "aws elastic ip miner" --gauge "loading..." 6 50 0 | |
ip=$(cat $tmp | cut -d: -f1) | |
allo=$(cat $tmp | cut -d: -f2) | |
(whiptail --title "aws elastic ip miner" --yesno --defaultno "keep $ip ?" 8 78) && | |
echo -e "ip: $ip \nallocation: $allo" || | |
discardip "$allo" | |
main | |
} | |
requirements aws whiptail | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
need something more aggressive?
let’s look for ec2 cidrs in ohio that have a 13 in them
then try and get em…
spoiler alert, they’re all taken D: