我的博客已迁移到xdoujiang.com请去那边和我交流一、基础环境1、版本cat /etc/debian_version 7.82、内核uname -r3.2.0-4-amd643、ip(eth0)10.1.10.1854、相关配置文件内容cat .config.iniaaa.aaa.combbb.bbb.comccc.ccc.comddd.ddd.comeee.eee.comfff.fff.com5、相关邮件脚本mailsend.py见http://7938217.blog.51cto.com/7928217/1708228二、具体代码1、cat checkcdn.sh#!/bin/bash#--------------------------------------------------#Author:jimmygong#Email:jimmygong@taomee.com#FileName:checkcdn.sh#Function:#Version:1.0#Created:2015-11-06#--------------------------------------------------sendip="10.1.10.185"maillog="/root/aa"mailpy="/root/mailsend.py"#PS:dig && curl need install[[ -e .config.ini ]] || exit 1function checkcdn (){ domain=$1 cdnchinache="https://portal.chinacache.com/serviceInfo/getChannelServiceInfo.do?username=111111&password=222222&channelName=http://$domain" cdnfastcdn="http://push.dnion.com/currentIp.do?username=111111&password=222222&domain=$domain" while read dname do num=$(dig ${dname}|grep ${dname}|grep -i "cname"|wc -l) [[ $num == 1 ]] && cdnname=$(dig ${dname}|grep ${dname}|grep -i "cname"|awk '{print $5}'|cut -d. -f3) [[ $num == 2 ]] && cdnname=$(dig ${dname}|grep ${dname}|grep -i "cname"|head -1|awk '{print $5}'|cut -d. -f4) if [[ $domain == $dname ]] then if [[ $cdnname == 'ccgslb' ]] then echo $cdnchinache elif [[ $cdnname == 'fastcdn' ]] then echo $cdnfastcdn fi fi done < .config.ini}function action (){ num=$(cat .config.ini|wc -l) for ((k=1;k<=${num};k++)) do domainname=$(cat .config.ini|sed -n "$k"p) for i in $domainname do cdnname=$(checkcdn $i) ips=`curl -s $cdnname` ipexclude="111.111.111.111 222.222.222.222.333.333.333.333" for ip in $ips do if [[ "$ipexclude" =~ "$ip" ]] then continue fi location=`curl -s www.cip.cc/$ip|awk /数据/|awk -F " " '{print $3,$5}'` echo $ip $location done done done> $maillog}function handlemail (){ sed -i -e '1i\IP\t地址\t运营商' $maillog sed -i -e 's/^//' -e 's/\s\+/<\/td>/' -e 's/\s\+/<\/td>/' -e 's/$/<\/td><\/tr>/' $maillog sed -i -e '1i\
三、效果