我正在尝试检查IP地址的反向查找,然后将结果写入txt文件。但我不知道如何将IP地址作为命令行参数(Linux环境)获取,而不是在脚本中写入IP。
我的剧本:
select wd.date, avg(h.Price)
from hourly h join
(select wd.date
from workdays wd
where wd.workday = 1 and wd.date <= curdate() -- you might want <
order by wd.date desc
limit 2
) wd2
on date(h.date) = wd.date
group by wd.date;
答案 0 :(得分:0)
您可以使用sys.argv
获取cli参数:
import sys, subprocess
cmd = 'dig -x %s @192.1.1.1' % sys.argv[1]
proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
out, err = proc.communicate()
with open("/tmp/test.txt", "w+") as f:
f.write(out)