找到全部中国大陆IP段

  可怜的学校的BBS,为了不让国外流量把计费器耗完,要找到全部中国大陆的IP段。首先是要有IP地址的数据,这在APNIC的网站上可以找到。
国家IP段数据下载地址:http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst
  有了数据就好办了,写几行程序,把其中大陆的ip段抽出来即可。
file = File.open(‘country-ipv4.lst’)
file.each do|line|
next if line =~ /^#/
items = line.split(‘ ‘)
puts “#{items[0]} – #{items[2]}” if items[6] == ‘cn’
end
  顺便试试ruby。

8 thoughts on “找到全部中国大陆IP段

  1. 冰封绝恋 November 15, 2009 / 1:46 am

    你好,非常感谢你提供的IP数据库下载地址,但是我想来很久也没有找到好的方法将中国的IP段分离出来。如果方便的话,麻烦博主帮我分离一份纯中国IP段,发到我的邮箱 iedoo#163.com 非常感谢!

  2. 万红荣 September 4, 2008 / 11:25 am

    呵呵 我的意思是我弄不清楚中国IP段具体是哪一段,在那个
    http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst
    里面看不出来 和你们不是一级别的人啦
    哎 实在是计算机网络知识贫乏的很,^_^
    114.28.0.0 – 114.28.255.255 : 114.28/16 : cn : 114.28.0 – 114.28.255 : APNIC
    114.111.0.0 – 114.111.31.255 : 114.111.0/19 : cn : 114.110.64 – 114.111.31 : APNIC
    .
    .
    .
    怎么会有这么多“cn”的呢?全部屏蔽?

  3. 万红荣 September 4, 2008 / 8:37 am

    我现在要屏蔽掉中国的IP,让中国地区的人不可以访问点击我的网站,我应该怎么办呢?
    本应自己对照着做,可是级别不够,希望能够详解!

  4. Season April 1, 2008 / 11:37 pm

    博主,我想请教下,我想屏蔽了中文系统的用户浏览我的计算机,但是我写入了代码后,所有语言系统都进入不到,应该怎么修改?
    window.load = runsys();
    function runsys(){
    if(navigator.systemlanguage = ‘zh-cn’){
    alert(‘网页已过期’);
    location.href=”http://www.QQ.com/index.asp”;
    } else{
    alert(navigator.systemlanguage);
    }
    }

  5. sd March 15, 2008 / 10:23 pm

    不是特别灵。

  6. D.c. July 24, 2007 / 3:33 pm

    今天刷出一行字,终于知道怎么回事了 ==
    我只知道我的ip不在网络中心使用的免费地址列表里,从现象上来说是说得过去的
    总之是谁提供的计数器就是谁在管收钱,要跟他们多沟通才行
    像bbs这种流量大的搞个包月的才是王道

  7. D.c. July 23, 2007 / 11:37 am

    没用的,关键还是要看网络中心
    ps. 竟然还是用的计费器 = =

  8. showsa July 21, 2007 / 3:00 pm

    竟然是用的计费器… –|||
    ps. 不是有包月帐号么?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s