I'm trying to check reverse lookup of IP address (argument). and then write the result to txt file.
 How I can check if the IP address (argument) is already registered in the file? If so, I need to get out of the script.

My script: 

```
import sys, os, re, shlex, urllib, subprocess 

cmd = 'dig -x %s @192.1.1.1' % sys.argv[1]

proc = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE)
out, err = proc.communicate()

# Convert to list of str lines
out = out.decode().split('\n')

# Only write the line containing "PTR"
with open("/tmp/test.txt", "w") as f:
 for line in out:
    if "PTR" in line:
        f.write(line)

```