RIR to DNS converter

RIR to DNS converter is a tool to convert Regional Internet Registry data to a DNS country lookup zone.
Download

RIR to DNS converter Ranking & Summary

Advertisement

  • Rating:
  • License:
  • GPL
  • Price:
  • FREE
  • Publisher Name:
  • Msquared
  • Publisher web site:

RIR to DNS converter Tags


RIR to DNS converter Description

RIR to DNS converter is a tool to convert Regional Internet Registry data to a DNS country lookup zone. RIR to DNS converter is a tool to convert Regional Internet Registry data to a DNS country lookup zone. You can use it to build your own DNS zone for looking up country codes from IP addresses.It uses data directly from RIPE, ARIN, APNIC, LACNIC, and AFRINIC. The data can be updated on a schedule of your choosing.The input data comes from: ftp://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-latest ftp://ftp.apnic.net/pub/stats/apnic/delegated-apnic-latest ftp://ftp.arin.net/pub/stats/arin/delegated-arin-latest ftp://ftp.ripe.net/pub/stats/ripencc/delegated-ripencc-latest ftp://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-latestThe input data format is described in: http://www.apnic.net/db/rir-stats-format.htmlThe output is a BIND 9 zone file that can be used to look up country codesin a similar fashion to in-addr.arpa. For example, to find out what country203.30.47.58 is: host 58.47.30.203.rir.example.com 58.47.30.203.rir.example.com has address 127.0.65.86where '65' and '85' are ASCII for 'A' and 'U', which means 203.30.47.58 isin Australia ('AU').HOW TO USE ITJust feed it the above delegated--latest files into stdin and it willspit out the zone file to stdout. The zone file will only have the IP addresses,so you could $INCLUDE it into a zone file that contains NS records, SOA, $ORIGIN,etc.WHY USE ITYou don't need the resolution of MaxMind's GeoIP database, but you do wantsomething that is free and you want it kept up to date on a schedule thatyou decide.You could use this to block or tag email based on countries, block or redirectvisitors to your website based on end-user country, and so on. Be verycareful about blocking mail this way, though, as you may block legitimateemail. Instead of blocking outright, use it in a SpamAssassin rule to addsomething to the spam level, based on where the email comes from.HOW IT WORKSThe RIR files contain ranges of IP addresses, and indicate what CC each range is allocated to. At the simplest level, rir2dns just sorts the ranges then iteratesthrough the IPs in each range and generates a reverse-dns-style A record thatrepresents the country code.HOW IT WORKS - IN DETAILRather than iterate through each IP address, the program tries to skip throughentire classes at a time (256 IPs, 65536 IPs, etc). Rather than iteratethrough each IP, the loop iterates through classes or IP ranges (whichever aresmaller at the loop control), using control-breaks to accummulate neighbouringranges where possible so that entire classes that are in the same country don'tgenerate huge numbers of records.Firstly, IPs are considered to be 4-digit numbers, but in base-256. In otherwords, each octet is dealt with as if it were a single base-256 digit. Thisturns out to be convenient because optimisations of large chunks of IP space can be done by looking for places where least-significant base-256 digits are zero.Next, IP ranges are broken down into the following sub-ranges: Optional individual IP addresses (ie: 4 octets) Optional A-class ranges (ie: 3 octets) Optional B-class ranges (ie: 2 octets) Optional C-class ranges (ie: 1 octet) Optional B-class ranges (ie: 2 octets) Optional A-class ranges (ie: 3 octets) Optional individual IP addresses (ie: 4 octets)Considering that there is a pattern here, I'm sure there's an elegant way tohandle breaking this down into two loops (one reducing the octets and oneincreasing the octets), but I can't be bothered, so I'll break it down intoseven loops. Kind of hard-coded, but at least it's simple.For ease of processing, the IP addresses are actually converted to 32-bit numbers, then back again. This simplifies mathematics and looping through ranges.That's pretty much it, really...Note that currently there are about 80,000 RIR records between all fiveregistries. This takes about 35 seconds on a 2.4GHz P4 to process, andgenerates a 26MB file with around 3/4 million lines (RRs). This causes BINDto use about 100MB or so of memory, and on a slow machine will probably cause it to take too long to reply, while it searches the zone. That size zone cantake a minute or two to load, which is quite a while.Basic algorithm: Read & process RIR data: Read RIR ranges Sort RIR ranges by start IP address Glue together contiguous ranges of the same country For each range Generate the IPs at the start of the range Generate the A-classes at the start of the range Generate the B-classes at the start of the range Generate the C-classes in the middle of the range Generate the B-classes at the end of the range Generate the A-classes at the end of the range Generate the IPs at the end of the range


RIR to DNS converter Related Software