rkn_ip_lookup 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +6 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/gems.locked +49 -0
- data/gems.rb +6 -0
- data/lib/rkn_ip_lookup.rb +12 -0
- data/lib/rkn_ip_lookup/checker.rb +30 -0
- data/lib/rkn_ip_lookup/config.rb +19 -0
- data/lib/rkn_ip_lookup/database.rb +65 -0
- data/lib/rkn_ip_lookup/provider.rb +13 -0
- data/lib/rkn_ip_lookup/provider/antizapret.rb +24 -0
- data/lib/rkn_ip_lookup/types/cidrs.rb +13 -0
- data/lib/rkn_ip_lookup/version.rb +3 -0
- data/rkn_ip_lookup.gemspec +31 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 13cc63944a5a42137590398cb248a16220c360565b29fec1c1785044eb72f077
|
4
|
+
data.tar.gz: 195893349abd7dd358a045204d6c72f8b6a882c4ea2c0bef467969318ba11b8a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b7fd85a5201743a8eceeceaee3a022708ac96d4cb36060017277e5631a1776e1a49a2c754174737d74bc501577f34a474541a7ac9b40b032e5f66a05f63c283
|
7
|
+
data.tar.gz: 6715156cbec61fd73c295fb46aad860f9ba6f4fc7f5d9c420720727cecba667eb0f125a5d6e007bccc15b1dbf1bd3af8a6950f7c990404c925748ad0cd316fb0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Sergey Besedin
|
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,48 @@
|
|
1
|
+
# Rkn IP/Hostname Lookup
|
2
|
+
|
3
|
+
Check IP or hostname presence in RKN blocked resources list.
|
4
|
+
Currently only antizapret.info supported (https://api.antizapret.info/group.php?data=ip).
|
5
|
+
Feel free to contribute
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rkn_ip_lookup'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rkn_ip_lookup
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
RknIpLookup::Checker.check('127.0.0.1') #=> false
|
26
|
+
RknIpLookup::Checker.check('google.com') #=> false
|
27
|
+
RknIpLookup::Checker.check('yandex.ru') #=> false
|
28
|
+
RknIpLookup::Checker.check('s3.eu-central-1.amazonaws.com') #=> #<IPAddr: IPv4:52.192.0.0/255.224.0.0>. This means IP was blocked by CIDR `52.192.0.0/11`
|
29
|
+
|
30
|
+
### Database
|
31
|
+
|
32
|
+
I use singleton `RknIpLookup::Database` to store fetched IPs. It caches by default with ruby marshal. To reset cache do
|
33
|
+
|
34
|
+
RknIpLookup::Database.reload
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
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.
|
39
|
+
|
40
|
+
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).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kressh/rkn_ip_lookup .
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rkn_ip_lookup'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require 'pry'
|
11
|
+
Pry.start
|
data/bin/setup
ADDED
data/gems.locked
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rkn_ip_lookup (0.1.0)
|
5
|
+
dry-configurable
|
6
|
+
faraday
|
7
|
+
pry
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
coderay (1.1.2)
|
13
|
+
concurrent-ruby (1.0.5)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
dry-configurable (0.7.0)
|
16
|
+
concurrent-ruby (~> 1.0)
|
17
|
+
faraday (0.15.0)
|
18
|
+
multipart-post (>= 1.2, < 3)
|
19
|
+
method_source (0.9.0)
|
20
|
+
multipart-post (2.0.0)
|
21
|
+
pry (0.11.3)
|
22
|
+
coderay (~> 1.1.0)
|
23
|
+
method_source (~> 0.9.0)
|
24
|
+
rake (10.5.0)
|
25
|
+
rspec (3.7.0)
|
26
|
+
rspec-core (~> 3.7.0)
|
27
|
+
rspec-expectations (~> 3.7.0)
|
28
|
+
rspec-mocks (~> 3.7.0)
|
29
|
+
rspec-core (3.7.1)
|
30
|
+
rspec-support (~> 3.7.0)
|
31
|
+
rspec-expectations (3.7.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.7.0)
|
34
|
+
rspec-mocks (3.7.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.7.0)
|
37
|
+
rspec-support (3.7.1)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
bundler (~> 1.16)
|
44
|
+
rake (~> 10.0)
|
45
|
+
rkn_ip_lookup!
|
46
|
+
rspec (~> 3.0)
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
1.16.1
|
data/gems.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module RknIpLookup
|
2
|
+
module Checker
|
3
|
+
class << self
|
4
|
+
def check(host_or_ip)
|
5
|
+
if host_or_ip.match?(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)
|
6
|
+
check_ip(host_or_ip)
|
7
|
+
else
|
8
|
+
check_host(host_or_ip)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def check_ip(ip)
|
13
|
+
db.ips.include?(ip) || db.cidrs.include?(ip) || false
|
14
|
+
end
|
15
|
+
|
16
|
+
def check_host(host)
|
17
|
+
ip = IPSocket.getaddress(host)
|
18
|
+
check_ip(ip)
|
19
|
+
rescue SocketError
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def db
|
26
|
+
Database.load
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'dry-configurable'
|
2
|
+
|
3
|
+
module RknIpLookup
|
4
|
+
module Config
|
5
|
+
def self.included(base)
|
6
|
+
base.instance_eval do
|
7
|
+
extend Dry::Configurable
|
8
|
+
|
9
|
+
setting :database do
|
10
|
+
setting :provider, :antizapret
|
11
|
+
setting :cache, true
|
12
|
+
setting :cache_file_path, 'tmp/cache/database.dump'
|
13
|
+
end
|
14
|
+
|
15
|
+
setting :logger, Logger.new(STDOUT), reader: true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require_relative 'types/cidrs'
|
2
|
+
|
3
|
+
module RknIpLookup
|
4
|
+
class Database
|
5
|
+
attr_accessor :data
|
6
|
+
attr_accessor :updated_at
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def load(skip_cache: false)
|
10
|
+
return @db if @db && !skip_cache
|
11
|
+
|
12
|
+
@db = !skip_cache && RknIpLookup.config.database.cache && load_from_file || new.load
|
13
|
+
@db
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(meth, *args)
|
17
|
+
load.public_send(meth)
|
18
|
+
end
|
19
|
+
|
20
|
+
def reload
|
21
|
+
load(skip_cache: true)
|
22
|
+
end
|
23
|
+
|
24
|
+
def load_from_file(filename = nil)
|
25
|
+
filename ||= RknIpLookup.config.database.cache_file_path
|
26
|
+
return unless File.exist? filename
|
27
|
+
@db = Marshal.load(File.read(filename))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def load
|
32
|
+
provider_data = RknIpLookup::Provider::Antizapret.fetch
|
33
|
+
self.data = provider_data.data
|
34
|
+
self.updated_at = Time.now
|
35
|
+
|
36
|
+
dump_to_file if RknIpLookup.config.database.cache
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def dump_to_file(filename = nil)
|
41
|
+
filename ||= RknIpLookup.config.database.cache_file_path
|
42
|
+
File.open(filename, 'w') do |f|
|
43
|
+
f.write Marshal.dump(self)
|
44
|
+
f.close
|
45
|
+
end
|
46
|
+
data
|
47
|
+
end
|
48
|
+
|
49
|
+
def ips
|
50
|
+
@ips ||= Set.new(entries.select { |x| x.match?(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) })
|
51
|
+
end
|
52
|
+
|
53
|
+
def cidrs
|
54
|
+
@cidrs ||= Types::Cidrs.new(entries.select { |x| x =~ %r{\.0/\d+} })
|
55
|
+
end
|
56
|
+
|
57
|
+
def hosts
|
58
|
+
@hosts ||= []
|
59
|
+
end
|
60
|
+
|
61
|
+
def entries
|
62
|
+
@entries ||= Set.new(data)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module RknIpLookup
|
4
|
+
class Provider
|
5
|
+
class Antizapret < Provider
|
6
|
+
DATABASE_URL = 'https://api.antizapret.info/group.php?data=ip'.freeze
|
7
|
+
|
8
|
+
attr_accessor :response, :data
|
9
|
+
|
10
|
+
def fetch
|
11
|
+
self.response = Faraday.get DATABASE_URL
|
12
|
+
self.data = parse_response
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def parse_response
|
18
|
+
response.body.split("\n").flat_map do |line|
|
19
|
+
line.split(',')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rkn_ip_lookup/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rkn_ip_lookup'
|
8
|
+
spec.version = RknIpLookup::VERSION
|
9
|
+
spec.authors = ['Sergey Besedin']
|
10
|
+
spec.email = ['kr3ssh@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Check server IP in RKN block lists}
|
13
|
+
spec.description = %q{Fuck RKN}
|
14
|
+
spec.homepage = ''
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'dry-configurable'
|
25
|
+
spec.add_dependency 'faraday'
|
26
|
+
spec.add_dependency 'pry'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rkn_ip_lookup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Besedin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dry-configurable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: Fuck RKN
|
98
|
+
email:
|
99
|
+
- kr3ssh@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- gems.locked
|
113
|
+
- gems.rb
|
114
|
+
- lib/rkn_ip_lookup.rb
|
115
|
+
- lib/rkn_ip_lookup/checker.rb
|
116
|
+
- lib/rkn_ip_lookup/config.rb
|
117
|
+
- lib/rkn_ip_lookup/database.rb
|
118
|
+
- lib/rkn_ip_lookup/provider.rb
|
119
|
+
- lib/rkn_ip_lookup/provider/antizapret.rb
|
120
|
+
- lib/rkn_ip_lookup/types/cidrs.rb
|
121
|
+
- lib/rkn_ip_lookup/version.rb
|
122
|
+
- rkn_ip_lookup.gemspec
|
123
|
+
- tmp/cache/.keep
|
124
|
+
homepage: ''
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.7.3
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: Check server IP in RKN block lists
|
148
|
+
test_files: []
|