article.txt

这个脚本能将文本中的ip地址批量ping之后将结果存在另一文件中,还挺实用的。

1
2
3
4
5
6
7
8
9
10
11
12
13

#!/bin/bash
output_file="ip_addresses.txt"
> $output_file # 清空输出文件(如果文件存在)
while read domain; do
ip=$(ping -c 1 -W 2 $domain | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}")
if [ -n "$ip" ]; then
echo "$domain -> $ip" >> $output_file
else
echo "$domain -> Unable to resolve" >> $output_file
fi
done < domains.txt

    Comments

    回到顶部