dns_zone_parser 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c77ae9aaf43c4ab035030fda483a0d77383fb13
4
+ data.tar.gz: 11790294db3618e8a18102797b1f0840937961c9
5
+ SHA512:
6
+ metadata.gz: 2b4bc5231883641f8ab19022915b91fb15b1bdee871419df99de7e1c2ed110fe8ea7ca53c64d6203621748be1e9c1d1aeb000e4210635c2381c7785f37f63807
7
+ data.tar.gz: e378e8d3c15f338429ffa962c4a2e70fc274ca475c8637fb0ea2dd2f6be13662b764e69ae8680c4fde14ce26bdf8396b036f0be5765beda43ef9adbaf6b46af6
@@ -0,0 +1,39 @@
1
+ *.gem
2
+ *.rbc
3
+
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to Mac
14
+ .idea/
15
+ *.DS_Store
16
+
17
+ ## Specific to RubyMotion:
18
+ .dat*
19
+ .repl_history
20
+ build/
21
+
22
+ ## Documentation cache and generated files:
23
+ /.yardoc/
24
+ /_yardoc/
25
+ /doc/
26
+ /rdoc/
27
+
28
+ ## Environment normalisation:
29
+ /.bundle/
30
+ /lib/bundler/man/
31
+
32
+ # for a library or gem, you might want to ignore these files since the code is
33
+ # intended to run in multiple environments; otherwise, check them in:
34
+ # Gemfile.lock
35
+ # .ruby-version
36
+ # .ruby-gemset
37
+
38
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
39
+ .rvmrc
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2012-2014 Arthur Ariel Sabintsev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,65 @@
1
+ # dns_zone_parser
2
+
3
+ ### About
4
+ This CLI-driven gem parses DNS Zone files in two ways:
5
+
6
+ - Parses all records into an array of DNS Record objects
7
+ - Outputs a CSV file
8
+
9
+ Zone file must be formatted in the following fashion:
10
+ ```
11
+ domain_name time_out IN record_type ip_address
12
+ ```
13
+
14
+ For example, zone files provided by [GoDaddy](http://www.godaddy.com) are listed in the above-mentioed format.
15
+
16
+ ### Release Notes (v1.0.0)
17
+ - Initial Release
18
+
19
+ ### Installation
20
+
21
+ ```ruby
22
+ gem 'dns_zone_parser'
23
+ ```
24
+
25
+ ### Terminal Execution
26
+ ```
27
+ ruby cli_rb path_to_zone_file
28
+ ```
29
+
30
+ ### Methods
31
+
32
+ #### Initializaiton
33
+ ``` ruby
34
+ dns_zone_parser = IdmeDNSZoneParser.new(ARGV[0])
35
+ ````
36
+
37
+ ### Write to CSV File
38
+ A CSV output named **parsed_dns_zone.csv** can be obtained by running the following command:
39
+
40
+ ``` ruby
41
+ dns_zone_parser = IdmeDNSZoneParser.new(ARGV[0])
42
+ dns_zone_parser.write_csv_file
43
+ ```
44
+
45
+ ### Obtain an Array of Records
46
+ This gem defines a model known as a `Record`. The record has five attributes:
47
+
48
+ ``` ruby
49
+ attr_accessor :domain
50
+ attr_accessor :time_out
51
+ attr_accessor :class_type
52
+ attr_accessor :record_type
53
+ attr_accessor :ip_address
54
+ ```
55
+
56
+ To obtain an array of all the records as `Record` objects in your project, run the following command
57
+
58
+ ``` ruby
59
+ dns_zone_parser = IdmeDNSZoneParser.new(ARGV[0])
60
+ records = dns_zone_parser.parse
61
+ ```
62
+
63
+ ### Credit
64
+
65
+ Created by [Arthur Ariel Sabintsev](http://www.sabintsev.com) for [ID.me](http://www.id.me)
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :console do
4
+ require 'pry'
5
+ require 'dns_zone_parser'
6
+ ARGV.clear
7
+ Pry.start
8
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ $:.push File.expand_path('../../lib', __FILE__)
3
+ require 'dns_zone_parser'
4
+
5
+ # Start DNS Zone Parser
6
+ dns_zone_parser = DnsZoneParser.new(ARGV[0])
7
+
8
+ # Get array of Record objects
9
+ records = dns_zone_parser.parse
10
+
11
+ # Write output file
12
+ dns_zone_parser.write_csv_file
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'dns_zone_parser/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "dns_zone_parser"
9
+ s.version = DnsZoneParser::VERSION
10
+ s.authors = ["Arthur Ariel Sabintsev"]
11
+ s.email = ["arthur@sabintsev.com"]
12
+ s.homepage = "https://github.com/IDme/ID.me-DNS-Zone-Parser"
13
+ s.summary = %q{CLI-driven tool that parses DNS Zone files in two ways; Reusable Ruby objects, and outputs a CSV file.}
14
+ s.description = s.summary
15
+ s.license = 'MIT'
16
+
17
+ s.files = `git ls-files`.split($/)
18
+ s.executables = ["dns_zone_parser"]
19
+ s.require_paths = ["lib"]
20
+ s.add_development_dependency "rake"
21
+
22
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'dns_zone_parser'
2
+
3
+ # Start DNS Zone Parser
4
+ dns_zone_parser = DnsZoneParser.new(ARGV[0])
5
+
6
+ # Get array of Record objects
7
+ records = dns_zone_parser.parse
8
+
9
+ # Write output file
10
+ dns_zone_parser.write_csv_file
@@ -0,0 +1,80 @@
1
+ require 'csv'
2
+ require_relative 'record'
3
+
4
+ class DnsZoneParser
5
+
6
+ attr_accessor :file_contents
7
+ attr_accessor :records
8
+
9
+ def initialize(filename)
10
+
11
+ raise StandardError, "\n\nUsage: dns_zone_parser <FILENAME>\n\n" if filename.nil?
12
+
13
+ @file_contents = File.open(filename).readlines
14
+ @records = []
15
+
16
+ end
17
+
18
+ def write_csv_file
19
+
20
+ parse_zone_file
21
+
22
+ CSV.open("parsed_dns_zone.csv", "w") do |csv|
23
+ @records.each do |record|
24
+
25
+ # Build array from Record object instance variables
26
+ record_array = []
27
+ record_array << record.record_type
28
+ record_array << record.class_type
29
+ record_array << record.domain
30
+ record_array << record.ip_address
31
+ record_array << record.time_out
32
+
33
+ csv << record_array
34
+
35
+ end
36
+ end
37
+
38
+ puts "Congratulations! Your zone file was parsed to a CSV file named: 'parsed_dns_zone.csv'."
39
+
40
+ end
41
+
42
+ def parse
43
+
44
+ # Parse zone file into sections delimited by class types
45
+ parse_zone_file
46
+
47
+ # Return the array of Record objects
48
+ @records
49
+
50
+ end
51
+
52
+ private
53
+
54
+ def parse_zone_file
55
+
56
+ @file_contents.each_with_index do |line, index|
57
+
58
+ # Each record in the zone file contains the following pattern: "\tIN\t"
59
+ if line.include? ("\tIN\t")
60
+
61
+ # Parse each record from the file and save it into a Record object
62
+ record = extract_record(line)
63
+
64
+ # Save each Record object into an array of Record objects
65
+ @records << record
66
+
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+
73
+ def extract_record(record)
74
+
75
+ # Create an Array object from the tab-delimited string
76
+ array_record = record.split(/\t/)
77
+ record = Record.new(array_record)
78
+ end
79
+
80
+ end
@@ -0,0 +1,3 @@
1
+ module DnsZoneParser
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ class Record
2
+
3
+ # Create accessor methods
4
+ attr_accessor :domain
5
+ attr_accessor :time_out
6
+ attr_accessor :class_type
7
+ attr_accessor :record_type
8
+ attr_accessor :ip_address
9
+
10
+ def initialize(array_record)
11
+
12
+ # Initialize instance variables
13
+ @domain = array_record[0]
14
+ @time_out = array_record[1]
15
+ @class_type = array_record[2]
16
+ @record_type = array_record[3]
17
+
18
+ # MX Records have an extra column before the IP Address block
19
+ if @class_type.eql?("MX")
20
+ @ip_address = array_record[5]
21
+ else
22
+ @ip_address = array_record[4]
23
+ end
24
+
25
+ if @ip_address.include?("\n")
26
+ @ip_address.delete!("\n") # Removes the "\n" character from the ip address
27
+ end
28
+
29
+ end
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dns_zone_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Arthur Ariel Sabintsev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: CLI-driven tool that parses DNS Zone files in two ways; Reusable Ruby
28
+ objects, and outputs a CSV file.
29
+ email:
30
+ - arthur@sabintsev.com
31
+ executables:
32
+ - dns_zone_parser
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".gitignore"
37
+ - LICENSE.md
38
+ - README.md
39
+ - Rakefile
40
+ - bin/dns_zone_parser
41
+ - dns_zone_parser.gemspec
42
+ - lib/cli.rb
43
+ - lib/dns_zone_parser.rb
44
+ - lib/dns_zone_parser/version.rb
45
+ - lib/record.rb
46
+ homepage: https://github.com/IDme/ID.me-DNS-Zone-Parser
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.2.2
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: CLI-driven tool that parses DNS Zone files in two ways; Reusable Ruby objects,
70
+ and outputs a CSV file.
71
+ test_files: []