#StackBounty: #bash #grep grep with PTR records and domain+TLD match

Bounty: 200

I’m trying to determine if the domain+TLD are present in a list, after running the host command for an IP.

My script looks like this:

while read ip; do
  PTR=$(host $ip | rev | cut -d" " -f1 | rev | sed 's/.$//')
  if grep -q "$PTR" list.txt
    echo "Match in list"
    echo "No match in list"
done <ips.txt

The list.txt will contain:


If I run my script for, which returns dns.google the script works as expected. If I run it for it will fail (not match) as the result is census4.shodan.io.

Is there a way I can have grep match only if the domain+TLD (in this case shodan.io) is in the list?

While census4.shodan.io should match the list.txt, a domain like shodan.io.example.net shouldn’t.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.