time nmap -n -iR 0 -sL | cut -d " " -f 5 | egrep -v "^10.*|^172.[16\-32].*|^192.168.*|^[224\-255].*" > RANDOM-IPS.txt
so the important part is:
egrep -v "^10.*|^172.[16\-32].*|^192.168.*|^[224\-255].*"
Q: Is this a good regexp? /So I will generate all the 2^32 IPv4 addresses, and "grep -v" the private/broadcast ranges./ Or are there any better ways to generate the usable IPv4 addresses on the internet?
[16\-32]doesn't mean what you think it means (did you even try it?). See this question for an example of matching numeric ranges with regexps. This is a pretty strange way of generating non-private IPv4 addresses (you missed some non-usable addresses by the way, such as loopback and the example ranges). Generating “all” IPv4 is a pretty silly goal anyway, what are you going to do with the result? – Gilles Oct 1 '11 at 18:45