代码示例,可以根据实际情况修改,

使用方法,./checkcode.sh  doamin.list

##domain.list为域名列表文件,一行一个不带http://的域名如 www.baidu.com cn.bing.com www.bilibili.com

效果

代码如下

#!/bin/bash
file=$1
#read -p "url file:" file
rm -rf code/*
for i in `cat $file`;
do
    # ipip=`ping $i -c 1 | head -1 | cut -d ' ' -f 3`
    ipip=`dig @223.5.5.5 $i +short |head -1 `
    httpcode=`curl -k -o /dev/null -s -m 20 -w %{http_code} $i --referer https://www.baidu.com --user-agent
    'Mozilla/5.0 (compatible; Baiduspider-render/2.0; +http://www.baidu.com/search/spider.html)' `
    if (( $httpcode == 200 )) ; then
        echo -e "\e[32m $httpcode ------ $i \t\t ($ipip) \e[0m"
    elif (( $httpcode == 302 || $httpcode == 301 )) ; then
        echo -e "\e[35m $httpcode ------ $i \t\t ($ipip) \e[0m"
    elif (( $httpcode == 400 || $httpcode == 403 || $httpcode == 401 || $httpcode == 404 )) ; then
        echo -e "\e[33m $httpcode ------ $i \t\t ($ipip) \e[0m"
    elif (( $httpcode == 500 || $httpcode == 502 || $httpcode == 503 )) ;then
        echo -e "\e[31m $httpcode ------ $i \t\t ($ipip) \e[0m"
    else
        echo -e "\e[37m $httpcode ------ $i \t\t ($ipip) \e[0m"
    fi
    echo -e $i "\t\t" $ipip >> code/$httpcode
done