Skip to content

Instantly share code, notes, and snippets.

@xero
Last active May 30, 2023 16:31
Show Gist options
  • Save xero/a73fc5eaf1064a980e8fc034181fc08a to your computer and use it in GitHub Desktop.
Save xero/a73fc5eaf1064a980e8fc034181fc08a to your computer and use it in GitHub Desktop.
aws ip miner
#!/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
@xero
Copy link
Author

xero commented May 29, 2023

need something more aggressive?

let’s look for ec2 cidrs in ohio that have a 13 in them

curl https://ip-ranges.amazonaws.com/ip-ranges.json > aws-ips.json
jq -r '.prefixes[] | select(.region=="us-east-2") | select(.service=="EC2") | .ip_prefix' aws-ips.json | grep 13

then try and get em…

#!/bin/bash
for i in {0..255}; do
	sleep 1
	r=$(AWS_PROFILE=dev aws ec2 allocate-address --region us-east-2 --address 3.13.137.$i 2>/dev/null)
	[ -z "$r" ] && echo "3.13.137.$i is taken" || echo "> 3.13.137.$i is mine!"
done

spoiler alert, they’re all taken D:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment