我正在尝试检查IP地址的反向查找(参数)。然后将结果写入txt文件。 如何检查IP地址(参数)是否已在文件中注册?如果是这样的话,我需要退出剧本。你知道吗
我的剧本:
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)
比如:
otherIps
包含list
上的ip地址,然后需要检查theIp
是否已经在otherIps
上,如果已经存在,请退出脚本。你知道吗如果文件不太大,可以执行以下操作:
现在,如果文件很大,并且希望避免可能的内存问题,可以使用^{} ,如下所示:
mmap.find(string[, start[, end]])
有很好的文档记录here。你知道吗相关问题 更多 >
编程相关推荐