shell-script(三)批量查询域名

知识点一:while–do–done 语句的运用

案例一:

知识点二:判断符号

1
2
3
4
5
6
7
8
9
10
11
-eq           //等于 equal

-ne //不等于 not equal

-gt //大于 (greater )

-lt //小于 (less)

-ge //大于等于

-le //小于等于

知识点三:数字的自增

var = $(($var + 1))

案例二:

扫描htb所有开放443端口的主机,查询到域名后,自动写入/etc/hosts

IP-out.txt is the list of IPs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
for line in $(cat IP-out.txt)
do
nmap -p443 --open ${line} >> https
#masscan -p443 -e tun0 $line --open #masscan扫描效果不佳
done
## scan open port ##

cat https | grep 10.10.10 > https_out
rm https
awk '{ print $5}' https_out > https
rm https_out
cat https | grep 10.10.10 > https_out #https_out file is important, it's contains all ips who opens 443 port
## clearing data ##

for IPs in $(cat https_out)
do
sslyze --regular ${IPs} --xml_out=${IPs}
done
## get domain ##

for IPs in $(cat https)
do
if ls /root/Desktop/$IPs/$IPs;then
echo '-------------'
mv $IPs /root/Desktop/$IPs
cat /root/Desktop/$IPs/$IPs | grep "Common Name" > /root/Desktop/$IPs/domain
Domain=`awk '{print $3}' /root/Desktop/$IPs/domain`
echo $IPs $Domain >> /etc/hosts
else
echo 'not found'
fi
done

cat /etc/hosts

/etc/hosts成功写入

但是运行展示效果不佳,以后学习如何写一个看起来整洁、美观、专业的shell script脚本。