#!/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 # 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