独舞

  • 首页
  • 程序开发
    • Java
    • 容器
    • 数据库
    • Javascirpt
    • 前端
  • Linux相关
  • 路由和网络
  • 苹果相关
  • 关于
    • 简历
独舞
记录那些朝花夕拾的日子……
  1. 首页
  2. 未分类
  3. 正文

通过Apanic解析中国IP

2016年11月1日 615点热度 3人点赞 0条评论
package com.ygsoft.bxj.api;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;

import org.apache.commons.io.FileUtils;

import com.google.common.collect.Lists;

/**
 * 
 * @author 吴云辉 fly@mmgg.net
 *
 */
public class Test {

	public static void main(String[] args) throws IOException {
		getFile();
		List<String> list = FileUtils.readLines(new File("e:/aa.txt"));
		List<String> ips = Lists.newArrayList();
		for (String string : list) {
			if (string.matches("^apnic\\|CN\\|ipv4\\|.+")) {
				String[] str = string.split("\\|");
				ips.add(str[3] + "/" + toMask(str[4]));
			}
		}
		for (String string : ips) {
			System.out.println("/ip firewall address-list add list=chinaips address=" + string);
		}
	}

	private static void getFile() throws IOException {
		URL url = new URL("http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest");
		FileUtils.copyURLToFile(url, new File("e:/aa.txt"));
	}

	private static int toMask(String rang) {
		int r = Integer.parseInt(rang);
		return (int) (32 - Math.log(r) / Math.log(2));
	}

}

标签: 暂无
最后更新:2016年11月1日

Phil

一直以来 我只有前进才能忘记羞辱的历史 所以 还有很多事情 需要我去做 也有很多事情 我必须要做

点赞
< 上一篇
下一篇 >
分类
  • Java / 32篇
  • Javascirpt / 1篇
  • Linux / 40篇
  • Mac / 2篇
  • 前端 / 4篇
  • 区块链 / 2篇
  • 容器 / 8篇
  • 数据库 / 1篇
  • 服务器主机 / 2篇
  • 未分类 / 12篇
  • 程序开发 / 1篇
  • 路由器 / 14篇
广告
广告

COPYRIGHT © 2021 mmgg.net. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

粤ICP备09207437号-5