#!/bin/bash
# This bash script implements a brute force method of ferreting out servers
# that support the gopher protocol. It visits randomized ips and tests if
# they respond to a gopher:// request.
#
# As with all of my content, PLEASE email me if you see anything I did
# wrong, or that I could do better, or if you have a different idea,
# or even just to say "HOWDY". My email address is in my <About Me>
# Start with $ nohup ~/bin/gopherret.sh &
# It will then restart automatically in background thanks to last line
# 1 second of nmap yields ~13680 random ips
# meaning that a single execution of the script lasts a bit over two hours on my machine.
timeout 1s nmap -n -iR 0 --exclude 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,224-255.-.-.- -sL >> ips
# Remove everything BUT the ip address from file ips
grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' ips | sponge ips
# This line indicates a new batch is being processed
echo "New batch of $(wc -l ips) scanned: $(date)" >> gophers
# Use curl on each random ip to see if anyone is listening on gopher://
while read address; do
eval "curl --max-time 1 gopher://$address"
if [ $? -eq 0 ]
then echo "$address">> gophers
fi
done <ips
# Tidy up and restart
rm ips
rm nohup.out
exec ~/bin/gopherret.sh
# NOTE: This is a L..O..N..G duration project!
# According to THIS page:
https://stackoverflow.com/questions/2437169/what-is-the-total-amount-of-public-ipv4-addresses
# there are LOTS and may more that are unused or inaccessible
# and this script takes a bit more than two hours to process
# around 10,000 of them. It may possibly NEVER bear fruit.
# As of this writing, I've checked ~40k with NO HITS YET.
#
# I would love it if you were silly enough to run this script too.
# the more gopherrets we have, the faster we can locate errant gophers!
#