全部中国大陆IP段

因为为了让大陆访问者看到本博的facebook和twitter
所以先得区分大陆访问者和非大陆访问者
首先要有所有中国大陆IP地址的数据
附上APNIC网站IP段数据下载地址

http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst

写个小程序把中国大陆的ip段全部抽取出来:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <string.h>
 
int main()
{
    freopen("country-ipv4.lst", "r", stdin);
    freopen("china-ipv4.txt", "w", stdout);
    char buf[1024], *pch, outch[64];
    while (gets(buf))
    {
        if (buf[0] == '#')
            continue;
        pch = strstr(buf, "cn");
        if (NULL == pch)
            continue;
        pch = strstr(buf, " :");
        strncpy(outch, buf, pch - buf);
        outch[pch - buf] = '\0';
        puts(outch);
    }
}

大家可以直接下载已经抽取出来的china-ipv4.txt (246)


One thought on “全部中国大陆IP段

  1. Pingback: 如何把FaceBook和Twitter显示给中国大陆用户 - 紫禁城

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>