知识点一:while–do–done 语句的运用
案例一:
知识点二:判断符号
| -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 done
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
for IPs in $(cat https_out) do sslyze --regular ${IPs} --xml_out=${IPs} done
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脚本。