You misunderstand regex syntax. [16-32]
does not mean "match 16, 17, ... or 32". It means "match one character which is either 1 or 2 or in the range 6-3" (which is not a valid range, hence the error).
It's possible to write a regex to match a range of integers, but it's complex and error prone. In your case, it would be much easier to use nmap
's --exclude
option to exclude the ranges you don't want. It understands CIDR notation, which is a much simpler way to describe the ranges you're talking about.
nmap -n -iR 0 --exclude 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,224-255.-.-.- -sL >RANDOM-IPS.txt
You didn't mention the loopback block (127.0.0.0/8), but you probably ought to exclude that too.
nmap
is being used to generate those random IP's, not the other way around. But I too am afraid to ask what they are getting fed INTO! Maybe it's a grand hunt for https only servers?