需求:
1.A表和B表匹配,找出A表中不存在于B表中的域名,称为结果C |
2.将结果C中的域名进行解析,得出对应解析IP,称为结果D |
3.将结果D得到的IP与公司IP进行匹配,筛选出属于公司IP的域名,得到最终结果E |
#!/bin/bash
rm baogao2.txt baogao.txt baobiao.txt c.txt jxip.txt tmp.ym 1&>/dev/null;
diff a.txt b.txt|sed '/^[0-9]/d' |awk '{print $2}'>c.txt ;
for line in `cat -A c.txt`;
do
ym=`echo $line |cut -d"^" -f1`;
nmap -F $ym >>tmp.ym ;
done
cat tmp.ym |grep "Nmap scan"|awk '{print $5$6}'|sed -n 's#(# #p' |sed -n 's#)# #p'|awk 'BEGIN{print "域名 IP地址"} {print$1 " " $2}'>jxip.txt;
for line in `cat -A ip.txt`;
do
ip=`echo $line |cut -d"^" -f1`;
grep $ip jxip.txt >>baobiao.txt;
done
cat baobiao.txt |sort|uniq >baobiao2.txt;
awk 'BEGIN{print "域名 IP地址"} {print$1 " " $2}' baobiao2.txt >baogao.txt;
脚本最终输出数据为baogao.txt文件,其它为文件为程序临时生成文件,保留是了排错,听同事说有特殊情况,因此保留数据做备。
听同事说他每天要花一个小时重复此项工作,因此写了此脚本,脚本基本实现了其需求,因此没有再进行深入优化,脚本中还有许多改进和优化的地方,多指教。
转载于:https://blog.51cto.com/jdonghong/1957919