Search for this pattern:
And replace it with this pattern:
Then add .in-addr.arpa at the end of each IP address.
I don’t think the plus signs are necessary; that was probably from when I was trying to figure out why I was only getting the first one or two numbers of some octets. For whatever reason, the regex pattern creates seven (or is it eight?) groups, and the correct groups are 1, 3, 5, and 7.
Once the addresses are in a text file, this following command will query each record in DNS and output the results in a comma separated format.
while read p; do gzz="echo $p,"; kla="dig ptr $p +short"; eval $gzz `$kla`; done < input.txt