1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
我的博客已迁移到xdoujiang.com请去那边和我交流
一、基础环境
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见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
1
function
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/^/<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
|
三、效果
本文转自 xdoujiang 51CTO博客,原文链接:http://blog.51cto.com/7938217/1710890,如需转载请自行联系原作者