ripecliner 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +34 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/ripecliner +11 -0
- data/bin/setup +8 -0
- data/lib/ripecliner.rb +7 -0
- data/lib/ripecliner/bgp_dump.rb +165 -0
- data/lib/ripecliner/cli.rb +56 -0
- data/lib/ripecliner/version.rb +3 -0
- data/ripecliner.gemspec +36 -0
- data/ripecliner.rb +1 -0
- metadata +121 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 0ecde0846c693990018fdd2cd13b84c3fe0de91d
|
|
4
|
+
data.tar.gz: e39f3058df69d4b43b7e96a6f898fbc960a6d648
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 31797d899be901e8daead6608b3e38a6a3aca5738738c03e33b62333e3f0d9b5b3ed46e316f73900a2021fee3c01566a63adbe8f828fb355542f8f792a55b87e
|
|
7
|
+
data.tar.gz: 3c663c2dac1b2eda1818ec3ac1b0770f52cb24a89013fe2bd4e06b614822a69cf5c1d4b43b8aab2b52140d97e1415bcfc494a8571a188b7e3728e47e7fef3a0c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Ihor Breza
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# RIPECLINER
|
|
2
|
+
|
|
3
|
+
This is CLI Downloader & Transformer for RIPE Routing Information Service
|
|
4
|
+
|
|
5
|
+
- `ripecliner` can download a RIPE BGP router dump
|
|
6
|
+
- `ripecliner` take a date as an option and pull down the latest file available from [RIPE RIS](https://www.ripe.net/analyse/internet-measurements/routing-information-service-ris)
|
|
7
|
+
- `ripecliner` transforms downloaded data into JSON from its "bgpdump" format
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
$ gem install ripecliner
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
./ripecliner.rb download <date>
|
|
19
|
+
./ripecliner.rb convert <file>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Development
|
|
23
|
+
|
|
24
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
25
|
+
|
|
26
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
27
|
+
|
|
28
|
+
## Contributing
|
|
29
|
+
|
|
30
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/defself/ripecliner.
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/ripecliner
ADDED
data/bin/setup
ADDED
data/lib/ripecliner.rb
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
require "open-uri"
|
|
2
|
+
require "csv"
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module RIPECLINER
|
|
6
|
+
|
|
7
|
+
class BGPDump
|
|
8
|
+
attr_writer :file
|
|
9
|
+
|
|
10
|
+
BASE_URL = "http://data.ris.ripe.net/rrc06"
|
|
11
|
+
DUMPS_URL = File.expand_path("../../dumps", File.dirname(__FILE__)).to_s
|
|
12
|
+
HEADERS = [:type,
|
|
13
|
+
:time,
|
|
14
|
+
:unknown1,
|
|
15
|
+
:from_ip,
|
|
16
|
+
:from_asn,
|
|
17
|
+
:prefix,
|
|
18
|
+
:aspath,
|
|
19
|
+
:origin,
|
|
20
|
+
:next_hop,
|
|
21
|
+
:unknown2,
|
|
22
|
+
:multi_exit_disc,
|
|
23
|
+
:community,
|
|
24
|
+
:atomic_aggregator,
|
|
25
|
+
:aggregator]
|
|
26
|
+
|
|
27
|
+
def download
|
|
28
|
+
show_progress("downloading") do
|
|
29
|
+
|
|
30
|
+
find_dump
|
|
31
|
+
|
|
32
|
+
unless File.exist? @file
|
|
33
|
+
begin
|
|
34
|
+
File.open(@file, "w") { |gz| IO.copy_stream(open(@url), gz) }
|
|
35
|
+
rescue OpenURI::HTTPError => e
|
|
36
|
+
puts e.message
|
|
37
|
+
previous_date!
|
|
38
|
+
download # try again
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def convert
|
|
46
|
+
show_progress("converting") do
|
|
47
|
+
|
|
48
|
+
find_dump
|
|
49
|
+
|
|
50
|
+
convert_to_csv
|
|
51
|
+
convert_to_json
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def date=(date)
|
|
57
|
+
digits = date ? date.scan(/\d/)
|
|
58
|
+
: []
|
|
59
|
+
now = Time.new.utc
|
|
60
|
+
|
|
61
|
+
date =
|
|
62
|
+
case digits.size
|
|
63
|
+
when 8
|
|
64
|
+
Time.utc(digits[0, 4].join, # %Y
|
|
65
|
+
digits[4, 2].join, # %m
|
|
66
|
+
digits[6, 2].join, # %d
|
|
67
|
+
now.hour)
|
|
68
|
+
when 0
|
|
69
|
+
now
|
|
70
|
+
else
|
|
71
|
+
raise ArgumentError.new("Wrong date format! Try: #{now.strftime("%Y.%m.%d")}")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
date = now if date > now
|
|
75
|
+
|
|
76
|
+
hour =
|
|
77
|
+
case date.hour
|
|
78
|
+
when 0...8 then "0000"
|
|
79
|
+
when 8...16 then "0800"
|
|
80
|
+
when 16...24 then "1600"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
@date = date.strftime("%Y%m%d.#{hour}")
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
private
|
|
87
|
+
|
|
88
|
+
def find_dump
|
|
89
|
+
use_date_from_file! unless @date
|
|
90
|
+
|
|
91
|
+
parent_dir = "/%{year}.%{month}" % { year: @date[0, 4],
|
|
92
|
+
month: @date[4, 2] }
|
|
93
|
+
dumps_parent_dir = DUMPS_URL + parent_dir
|
|
94
|
+
filename = "/bview.#{@date}.gz"
|
|
95
|
+
|
|
96
|
+
unless File.exist? dumps_parent_dir
|
|
97
|
+
FileUtils.mkdir dumps_parent_dir
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
@file = dumps_parent_dir + filename
|
|
101
|
+
@url = BASE_URL + parent_dir + filename
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def convert_to_csv
|
|
105
|
+
gz = @file
|
|
106
|
+
download unless File.exist? gz
|
|
107
|
+
|
|
108
|
+
@file = "#{@file.split(".")[0...-1].join(".")}.csv" # replace extension to .csv
|
|
109
|
+
|
|
110
|
+
unless File.exist? @file
|
|
111
|
+
`bgpdump -t change -m -O #{@file} #{gz}`
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def convert_to_json
|
|
116
|
+
csv_file = @file
|
|
117
|
+
@file = "#{@file.split(".")[0...-1].join(".")}.json" # replace extension to .json
|
|
118
|
+
|
|
119
|
+
File.open(@file, "w") do |json|
|
|
120
|
+
json.puts "["
|
|
121
|
+
|
|
122
|
+
CSV.open(csv_file, "r") do |csv|
|
|
123
|
+
while row = csv.shift
|
|
124
|
+
hash_row = Hash[HEADERS.zip row[0].split("|", -1)]
|
|
125
|
+
separator = csv.eof? ? ""
|
|
126
|
+
: ","
|
|
127
|
+
json_row = JSON.pretty_generate(hash_row, indent: " ").sub!(/^}$/, " }#{separator}")
|
|
128
|
+
json.puts " %s" % json_row
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
json.puts "]"
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def use_date_from_file!
|
|
137
|
+
@date = @file.split(".")[2, 2].join(".") # extract date from filename
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def show_progress(message, &block)
|
|
141
|
+
print message
|
|
142
|
+
|
|
143
|
+
bar = Thread.new do
|
|
144
|
+
loop do
|
|
145
|
+
print "."
|
|
146
|
+
sleep 0.5
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
block.call
|
|
151
|
+
|
|
152
|
+
bar.kill
|
|
153
|
+
puts "[ OK ]"
|
|
154
|
+
puts "Dump was successfully saved at #{@file}"
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def previous_date!
|
|
158
|
+
format = "%Y%m%d.%H00"
|
|
159
|
+
current_date = Time.strptime(@date, format)
|
|
160
|
+
eight_hours = 8 * 60 * 60
|
|
161
|
+
@date = (current_date - eight_hours).strftime(format)
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module RIPECLINER
|
|
2
|
+
|
|
3
|
+
class CLI
|
|
4
|
+
|
|
5
|
+
def initialize(params)
|
|
6
|
+
@command = params[0]
|
|
7
|
+
@argument = params[1]
|
|
8
|
+
|
|
9
|
+
invoke_command
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def invoke_command
|
|
13
|
+
case @command
|
|
14
|
+
when "download"
|
|
15
|
+
dump = RIPECLINER::BGPDump.new
|
|
16
|
+
dump.date = @argument
|
|
17
|
+
dump.download
|
|
18
|
+
when "convert"
|
|
19
|
+
dump = RIPECLINER::BGPDump.new
|
|
20
|
+
|
|
21
|
+
if @argument
|
|
22
|
+
dump.file = @argument
|
|
23
|
+
else
|
|
24
|
+
raise ArgumentError.new("Please, specify dump file for converting / downloading.")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
dump.convert
|
|
28
|
+
when "-h", "--help"
|
|
29
|
+
CLI.print_help
|
|
30
|
+
when "-v", "--version"
|
|
31
|
+
puts RIPECLINER::VERSION
|
|
32
|
+
else
|
|
33
|
+
raise ArgumentError.new("Unrecognized command")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.print_help
|
|
38
|
+
puts <<~HELP
|
|
39
|
+
ripecliner is a CLI Downloader & Transformer for RIPE Routing Information Service
|
|
40
|
+
|
|
41
|
+
Usage:
|
|
42
|
+
bin/ripecliner -h/--help
|
|
43
|
+
bin/ripecliner -v/--version
|
|
44
|
+
bin/ripecliner command [argument]
|
|
45
|
+
|
|
46
|
+
Examples:
|
|
47
|
+
bin/ripecliner download <date>
|
|
48
|
+
bin/ripecliner convert <file>
|
|
49
|
+
|
|
50
|
+
Further information:
|
|
51
|
+
https://github.com/defself/ripecliner
|
|
52
|
+
HELP
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
data/ripecliner.gemspec
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'ripecliner/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "ripecliner"
|
|
8
|
+
spec.version = RIPECLINER::VERSION
|
|
9
|
+
spec.authors = ["Ihor Breza"]
|
|
10
|
+
spec.email = ["seniorigor@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{CLI Downloader & Transformer for RIPE Routing Information Service.}
|
|
13
|
+
spec.homepage = "https://github.com/defself/ripecliner"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
if spec.respond_to?(:metadata)
|
|
17
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
|
18
|
+
else
|
|
19
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
20
|
+
"public gem pushes."
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
24
|
+
f.match(%r{^(test|spec|features)/})
|
|
25
|
+
end
|
|
26
|
+
spec.bindir = "bin"
|
|
27
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ["lib", "dumps"]
|
|
29
|
+
|
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
33
|
+
spec.add_development_dependency "pry", "~> 0.10.4"
|
|
34
|
+
|
|
35
|
+
spec.required_ruby_version = ">= 2.3.0"
|
|
36
|
+
end
|
data/ripecliner.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
./bin/ripecliner
|
metadata
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ripecliner
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ihor Breza
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-10-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.13'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.13'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: pry
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.10.4
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 0.10.4
|
|
69
|
+
description:
|
|
70
|
+
email:
|
|
71
|
+
- seniorigor@gmail.com
|
|
72
|
+
executables:
|
|
73
|
+
- console
|
|
74
|
+
- ripecliner
|
|
75
|
+
- setup
|
|
76
|
+
extensions: []
|
|
77
|
+
extra_rdoc_files: []
|
|
78
|
+
files:
|
|
79
|
+
- ".gitignore"
|
|
80
|
+
- ".rspec"
|
|
81
|
+
- ".travis.yml"
|
|
82
|
+
- Gemfile
|
|
83
|
+
- LICENSE.txt
|
|
84
|
+
- README.md
|
|
85
|
+
- Rakefile
|
|
86
|
+
- bin/console
|
|
87
|
+
- bin/ripecliner
|
|
88
|
+
- bin/setup
|
|
89
|
+
- lib/ripecliner.rb
|
|
90
|
+
- lib/ripecliner/bgp_dump.rb
|
|
91
|
+
- lib/ripecliner/cli.rb
|
|
92
|
+
- lib/ripecliner/version.rb
|
|
93
|
+
- ripecliner.gemspec
|
|
94
|
+
- ripecliner.rb
|
|
95
|
+
homepage: https://github.com/defself/ripecliner
|
|
96
|
+
licenses:
|
|
97
|
+
- MIT
|
|
98
|
+
metadata:
|
|
99
|
+
allowed_push_host: https://rubygems.org
|
|
100
|
+
post_install_message:
|
|
101
|
+
rdoc_options: []
|
|
102
|
+
require_paths:
|
|
103
|
+
- lib
|
|
104
|
+
- dumps
|
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: 2.3.0
|
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
|
+
requirements:
|
|
112
|
+
- - ">="
|
|
113
|
+
- !ruby/object:Gem::Version
|
|
114
|
+
version: '0'
|
|
115
|
+
requirements: []
|
|
116
|
+
rubyforge_project:
|
|
117
|
+
rubygems_version: 2.6.6
|
|
118
|
+
signing_key:
|
|
119
|
+
specification_version: 4
|
|
120
|
+
summary: CLI Downloader & Transformer for RIPE Routing Information Service.
|
|
121
|
+
test_files: []
|