批量ping域名获取ip

论坛 期权论坛 脚本     
匿名技术用户   2020-12-22 07:45   35   0

1、先把域名文件整理成每行一个域名的形式
2、在shell脚本里遍历域名文件每一行即每一个域名
3、通过 ping ${domain} -c 1|sed '1{s/[^(]*(//;s/).*//;q}' 语句截取ping结果获取域名解析ip

#!/bin/bash

n=1

for domain in `cat domains_arr.txt`
do
    ip=`ping ${domain} -c 1|sed '1{s/[^(]*(//;s/).*//;q}'`
    echo -e $n "\t" $domain "\t" $ip
    if [ "$ip" != "47.91.149.228" ]
    then
        echo -e $domain"\t"$ip >> chk_fail.txt
    fi
    n=$(($n+1))
done
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP