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 then echo "Match in list" else echo "No match in list" fi done <ips.txt
list.txt will contain:
If I run my script for 22.214.171.124, which returns dns.google the script works as expected. If I run it for 126.96.36.199 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.