根据其国家/地区区域合并多个IPv4地址块 [英] merging of multiple IPv4 address blocks on the basis of their country region

查看:230
本文介绍了根据其国家/地区区域合并多个IPv4地址块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有CIDR表示形式的IPv4块。这些街区根据城市划分我希望将它们合并一级,我的意思是区域级别
例如

I have IPv4 blocks in the CIDR notation form. These blocks are divided on the basis of city I want to merge them one level up I mean till region level e.g

12.17.230.48|12.178.230.63|US|Texas|Temple
12.178.230.64|12.178.230.95|US|Texas|Abilene
12.178.230.96|12.178.230.111|US|Texas|Jayton
12.178.230.112|12.178.230.119|US|Texas|Wichita Falls
12.178.230.120|12.178.230.127|US|Texas|Mansfield
12.178.230.128|12.178.230.159|US|Texas|Waco (Bellmead)
12.178.230.160|12.178.230.167|US|Texas|Irving
12.178.230.168|12.178.230.175|US|Texas|Fort Worth
12.178.230.176|12.178.230.183|US|Texas|Alvarado
12.178.230.184|12.178.230.191|US|Texas|Weatherford
12.178.230.192|12.178.230.199|US|Texas|Haltom City
12.178.230.200|12.178.230.207|US|Texas|Fort Worth (Diamond Hill -    Jarvis)
12.178.230.208|12.178.230.223|US|Texas|Fort Worth
12.178.230.224|12.178.230.231|US|Texas|Coppell
12.178.230.232|12.178.230.239|US|Texas|Lubbock   

这里所有去德克萨斯州所以我想将所有这些块合并到这样的一个

here All goes to Texas so I want to merge all those blocks in to one like this

start_ip_of_first_range|end_ip_of_last_range_of_same_region|US|Texas

虽然我试图这看起来我甚至违反了IPv4地址的基本规则

Though I tried to this but looks like I was even violating IPv4 addresses fundamental rule

请建议任何公式?

推荐答案

很晚才写到这里,但我找到了一种简单而漫长的方法来实现这个目标。

Well Its late to write here , But I found a simple and lengthy way to achieve this objective.

 1. First convert all the ranges in the form of network_address|subnet_mask
 2. sort whole the file in descending IP address
 3. Now check if two lines fulfill following conditions 
  a. Same subnet mast &&
  b. Re-Check network IP if the position of first set bit from right is greater than host bit length &&
  c. Network IP of the line = network ip of next line + 2^(number of host bit) +1 &&
  d. First set bit from right in first line should be equal and less than the first set bit in next line's IP. &&
  e. Both line should have same location &&
4. In that case remove the next line and decrease the subnet mask length by one.
5. Now the resultant range will serve exactly same IP addresses as much the initial two ranges were serving neither more or less .
6. To make more merging keep repeating step 2 to 5 

我是这样做的C程序和bash实用程序。虽然我没有在这里粘贴程序如果有人需要它我将尝试在这里提出确切的解决方案。

I did this using a C program and bash utilities . Though I am not pasting program here If someone needs it I will try to put here the exact solution.

这可能是着名问题的解决方案 http://www.perlmonks.org/?node_id=118346

This might be solution of famous problem http://www.perlmonks.org/?node_id=118346

这篇关于根据其国家/地区区域合并多个IPv4地址块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆