一、基本环境 1、版本 cat /etc/debian_version 7.8 2、内核 uname -r 3.2.0-4-amd64 3、ip(eth0) 10.1.10.185 4、相干配置文件内容 cat .config.ini aaa.aaa.com bbb.bbb.com ccc.ccc.com ddd.ddd.com eee.eee.com fff.fff.com 5、相干邮件脚本 mailsend.py见https://7938217.blog.51cto.com/7928217/1708228 二、具体代码 1、cat checkcdn.sh #!/bin/bash #-------------------------------------------------- #Author:jimmygong #Email:[email protected] #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 1 function checkcdn () { domain=cdnchinache="https://portal.chinacache.com/serviceInfo/getChannelServiceInfo.do?username=111111&password=222222&channelName=https://$domain" cdnfastcdn="https://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 }"|cut -d. -f3) [[ $num == 2 ]] && cdnname=$(dig ${dname}|grep ${dname}|grep -i "cname"|head -1|awk "{print }"|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 ,}"` echo $ip $location done done done> $maillog } function handlemail () { sed -i -e "1i\IP\t地址\t运营商" $maillog sed -i -e "s/^/<tr><td>/" -e "s/\s\+/<\/td><td>/" -e "s/\s\+/<\/td><td>/" -e "s/$/<\/td><\/tr>/" $maillog sed -i -e "1i\<table>" -e "$a\</table>" $maillog sed -i -e "1i\<style type="text\/css">table,td,th{border:1px solid black;}<\/style>" $maillog python $mailpy $maillog "一、基本环境 1、版本 cat /etc/debian_version 7.8 2、内核 uname -r 3.2.0-4-amd64 3、ip(eth0) 10.1.10.185 4、相干配置文件内容 cat .config.ini aaa.aaa.com bbb.bbb.com ccc.ccc.com ddd.ddd.com eee.eee.com fff.fff.com 5、相干邮件脚本 mailsend.py见https://7938217.blog.51cto.com/7928217/1708228 二、具体代码 1、cat checkcdn.sh #!/bin/bash #-------------------------------------------------- #Author:jimmygong #Email:[email protected] #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 1 function checkcdn () { domain=$1 cdnchinache="https://portal.chinacache.com/serviceInfo/getChannelServiceInfo.do?username=111111&password=222222&channelName=https://$domain" cdnfastcdn="https://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/^/<tr><td>/" -e "s/\s\+/<\/td><td>/" -e "s/\s\+/<\/td><td>/" -e "s/$/<\/td><\/tr>/" $maillog sed -i -e "1i\<table>" -e "$a\</table>" $maillog sed -i -e "1i\<style type="text\/css">table,td,th{border:1px solid black;}<\/style>" $maillog python $mailpy $maillog "$0 $sendip" } action handlemail exit 0三、后果
本篇文章出自 “7928217” 博客,请务必保存此来路https://7938217.blog.51cto.com/7928217/1710890
一、基本环境 1、版本 cat /etc/debian_version 7.8 2、内核 uname -r 3.2.0-4-amd64 3、ip(eth0) 10.1.10.185 4、相干配置文件内容 cat .config.ini aaa.aaa.com bbb.bbb.com ccc.ccc.com ddd.ddd.com eee.eee.com fff.fff.com 5、相干邮件脚本 mailsend.py见https://7938217.blog.51cto.com/7928217/1708228 二、具体代码 1、cat checkcdn.sh #!/bin/bash #-------------------------------------------------- #Author:jimmygong #Email:[email protected] #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 1 function checkcdn () { domain=$1 cdnchinache="https://portal.chinacache.com/serviceInfo/getChannelServiceInfo.do?username=111111&password=222222&channelName=https://$domain" cdnfastcdn="https://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/^/<tr><td>/" -e "s/\s\+/<\/td><td>/" -e "s/\s\+/<\/td><td>/" -e "s/$/<\/td><\/tr>/" $maillog sed -i -e "1i\<table>" -e "$a\</table>" $maillog sed -i -e "1i\<style type="text\/css">table,td,th{border:1px solid black;}<\/style>" $maillog python $mailpy $maillog "$0 $sendip" } action handlemail exit 0
三、后果
本篇文章出自 “7928217” 博客,请务必保存此来路https://7938217.blog.51cto.com/7928217/1710890
$sendip" } action handlemail exit 0一、基本环境 1、版本 cat /etc/debian_version 7.8 2、内