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
|
#!/bin/bash
#getip
#connect wy.cn
FILE=delegated-apnic-latest
if
[ ! -f $FILE ];
then
wget http:
//ftp
.apnic.net
/apnic/stats/apnic/delegated-apnic-latest
fi
grep
"apnic|CN|ipv4"
$FILE |
awk
-F
"|"
'{print $4,$5}'
> IP.txt
AB=`
cat
IP.txt |
wc
-l`
pow=32
i=1
while
(($i<=$AB));
do
IP=`
sed
-n ${i}p IP.txt |
awk
'{print $1}'
`
HOST=`
sed
-n ${i}p IP.txt |
awk
'{print $2}'
`
ERHOST=`
echo
"obase=2;$HOST"
|
bc
`
HOSTL=`
echo
${
#ERHOST}`
let
BU=$pow-$HOSTL
ZQIAN=
"11111111111111111111111111111111"
QIAN=`
echo
${ZQIAN:0:$BU}`
MASK=`
echo
$QIAN$ERHOST`
STRA=`
echo
${MASK:0:8}`
STRB=`
echo
${MASK:8:8}`
STRC=`
echo
${MASK:16:8}`
STRD=`
echo
${MASK:24:8}`
MASKA=`
echo
"ibase=2;$STRA"
|
bc
`
MASKB=`
echo
"ibase=2;$STRB"
|
bc
`
MASKC=`
echo
"ibase=2;$STRC"
|
bc
`
MASKD=`
echo
"ibase=2;$STRD"
|
bc
`
NETMASK=`
echo
$MASKA.$MASKB.$MASKC.$MASKD`
BIT=`
echo
$MASK |
grep
-o
'1'
|
wc
-l`
NET=`whois -h whois.apnic.net $IP |
grep
"mnt-by"
`
NUM_A=`
echo
$NET |
grep
'CHINA'
|
wc
-l`
NUM_B=`
echo
$NET |
grep
'CNCGROUP'
|
wc
-l`
NUM_C=`
echo
$NET |
grep
'CERNET'
|
wc
-l`
NUM_D=`
echo
$NET |
grep
'CMCC'
|
wc
-l`
if
(($NUM_A>0));
then
echo
$IP/$NETMASK ................CHINATELECOM
echo
$IP/$NETMASK >> CHINATELECOM.TXT
let
i++
continue
fi
if
(($NUM_A>0));
then
echo
$IP/$NETMASK ................CHINATELECOM
echo
$IP/$NETMASK >> CHINATELECOM.TXT
let
i++
continue
fi
if
(($NUM_B>0));
then
echo
$IP/$NETMASK ................CNCGROUP
echo
$IP/$NETMASK >> CNCGROUP.TXT
let
i++
continue
fi
if
(($NUM_C>0));
then
echo
$IP/$NETMASK ................CERNET
echo
$IP/$NETMASK >> CERNET.TXT
let
i++
continue
fi
if
(($NUM_D>0));
then
echo
$IP/$NETMASK ................CMCC
echo
$IP/$NETMASK >> CMCC.TXT
let
i++
continue
fi
let
res=$NUM_A+$NUM_B+$NUM_C+$NUM_D
if
(($res==0));
then
echo
$IP/$NETMASK ................OTHER
echo
$IP/$NETMASK >> OTHER.TXT
let
i++
fi
done
rm
-rf IP.txt $FILE
|
得到IP地址文件分类如下
CERNET.TXT CHINATELECOM.TXT CMCC.TXT CNCGROUP.TXT OTHER.TXT getip
CERNET.TXT是教育网
CHINATELECOM.TXT是中国电信
CMCC.TXT是中国移动
CNCGROUP是中国联通
OTHER.TXT是其他的 大部分是CNNIC分配的IP地址
getip是脚本文件名
如果找不到whois命令 从如下地址下载安装
http://ftp.apnic.net/apnic/dbase/tools/ripe-dbase-client-v3.tar.gz
本文转自flyingzf 51CTO博客,原文链接:http://blog.51cto.com/flyingzf/1331191,如需转载请自行联系原作者