一个 txt 文档中每行一个IP地址请写一段 shell 脚本读取每个ip地址验证其 host 中是否包含字符串 google
可以使用以下脚本:
#!/bin/bash
# 读取IP地址文件
while read ip; do
# 获取host信息
host_info=$(host $ip)
# 判断host信息中是否包含"google."
if echo $host_info | grep -q "google."; then
echo "$ip contains google."
else
echo "$ip does not contain google."
fi
done < ip_addresses.txt
其中,while read ip; do 用于逐行读取IP地址文件中的每个IP地址,host_info=$(host $ip) 用于获取该IP地址对应的host信息,if echo $host_info | grep -q "google."; then 判断host信息中是否包含"google.",如果包含则输出"$ip contains google.",否则输出"$ip does not contain google."。
注意,执行该脚本前需要保证 host 命令已经安装。另外,IP地址文件需要与脚本在同一目录下,并命名为 ip_addresses.txt
原文地址: https://www.cveoy.top/t/topic/e5gU 著作权归作者所有。请勿转载和采集!