blocklistshow 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/.rubocop.yml +42 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/Makefile +7 -0
- data/README.md +37 -0
- data/bin/blocklist.rb +174 -0
- data/bin/geodb-lookup.rb +34 -0
- metadata +55 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 46d7101d4cdf766ddc1d332f752a4c2982acd54643404cc00483d56a1d05712b
|
4
|
+
data.tar.gz: 36600a16f4683373926827f8cb8654629dff00ba51281a6a3bdc151cebf2d006
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8823bb78fb271dac8bd7703507221e0f30e3ebdfd2ac4cec1a97dd3cccbece4957509d6c8e9ccf8b2b5ccf1cd3d61578ef3ea71984425541151e2c24c925ca02
|
7
|
+
data.tar.gz: 9b7152a0d4167660e3d1ae67d6e8e26dce9bc91a6dc0e183175a628b17070b84555493e16ace16036c927956c7e4f23691a21eff38e06eb238663ea9af4b6ff3
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
# rubocop configuration
|
4
|
+
|
5
|
+
Layout/SpaceInsideArrayLiteralBrackets:
|
6
|
+
EnforcedStyle: space
|
7
|
+
Exclude:
|
8
|
+
- 'blocklistshow.gemspec'
|
9
|
+
|
10
|
+
Layout/SpaceInsideParens:
|
11
|
+
EnforcedStyle: space
|
12
|
+
Exclude:
|
13
|
+
- 'blocklistshow.gemspec'
|
14
|
+
|
15
|
+
Layout/SpaceInsideRangeLiteral:
|
16
|
+
#EnforcedStyle: space
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Layout/SpaceInsideReferenceBrackets:
|
20
|
+
EnforcedStyle: space
|
21
|
+
Exclude:
|
22
|
+
- 'blocklistshow.gemspec'
|
23
|
+
|
24
|
+
Metrics/LineLength:
|
25
|
+
Exclude:
|
26
|
+
- 'blocklistshow.gemspec'
|
27
|
+
|
28
|
+
Style/FrozenStringLiteralComment:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/RegexpLiteral:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/SpecialGlobalVars:
|
35
|
+
EnforcedStyle: use_perl_names
|
36
|
+
|
37
|
+
Style/SymbolArray:
|
38
|
+
EnforcedStyle: brackets
|
39
|
+
|
40
|
+
Style/WordArray:
|
41
|
+
EnforcedStyle: brackets
|
42
|
+
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2018-2019 Dirk Meyer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Makefile
ADDED
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Blocklist
|
2
|
+
|
3
|
+
Display of data from blocklistd on FreeBSD with country codes and reverse DNS.
|
4
|
+
The reverse DNS and the country codes are cached.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Install it on the server running blocklistd by:
|
9
|
+
|
10
|
+
$ pkg install databases/ruby-bdb net/webalizer-geodb
|
11
|
+
$ gem install blocklist
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
########################
|
16
|
+
# Example 1 Full list
|
17
|
+
########################
|
18
|
+
|
19
|
+
$ blocklist.rb
|
20
|
+
|
21
|
+
###############################
|
22
|
+
# Example 2 Filtered by port
|
23
|
+
###############################
|
24
|
+
|
25
|
+
$ blocklist.rb 25
|
26
|
+
|
27
|
+
#######################################
|
28
|
+
# Example 3 Filtered by country code
|
29
|
+
#######################################
|
30
|
+
|
31
|
+
$ blocklist.rb eu
|
32
|
+
|
33
|
+
### File formats
|
34
|
+
|
35
|
+
The cache files are stored as JSON.
|
36
|
+
The Geolocation datebase is a Berkeley DB file.
|
37
|
+
|
data/bin/blocklist.rb
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
require 'ipaddr'
|
4
|
+
require 'json'
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
DNS_CACHE_FILE = '/var/db/blacklistd.dns.json'.freeze
|
8
|
+
CC_CACHE_FILE = '/var/db/blacklistd.cc.json'.freeze
|
9
|
+
|
10
|
+
# pkg install databases/ruby-bdb net/webalizer-geodb
|
11
|
+
GEODB_FILE = '/usr/local/share/geolizer/GeoDB.dat'.freeze
|
12
|
+
|
13
|
+
def get_dns( ip )
|
14
|
+
return @dns_cache[ ip ] if @dns_cache.key?( ip )
|
15
|
+
|
16
|
+
result = nil
|
17
|
+
`host '#{ip}'`.split( "\n" ).each do |line|
|
18
|
+
return 'not found' if line =~ /not found/
|
19
|
+
return line.split( /\s/ ).last if line =~ /domain name pointer/
|
20
|
+
|
21
|
+
result = line
|
22
|
+
end
|
23
|
+
result
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_cached_dns( ip )
|
27
|
+
return @dns_cache[ ip ] if @dns_cache.key?( ip )
|
28
|
+
|
29
|
+
@dns_cache[ ip ] = get_dns( ip )
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_whois( ip )
|
33
|
+
country = nil
|
34
|
+
last = nil
|
35
|
+
inetnum = false
|
36
|
+
`whois '#{ip}'`.force_encoding( 'BINARY' ).split( "\n" ).each do |line|
|
37
|
+
# pp line
|
38
|
+
case line
|
39
|
+
when /^$/
|
40
|
+
inetnum = false
|
41
|
+
when /^inetnum:/i
|
42
|
+
inetnum = true
|
43
|
+
when /^country:/i
|
44
|
+
last = line.split( ':', 2 ).last.strip
|
45
|
+
next unless inetnum
|
46
|
+
|
47
|
+
country = last
|
48
|
+
end
|
49
|
+
end
|
50
|
+
country = last if country.nil?
|
51
|
+
country
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_cached_whois( ip )
|
55
|
+
return @cc_cache[ ip ] if @cc_cache.key?( ip ) && !@cc_cache[ ip ].nil?
|
56
|
+
|
57
|
+
@cc_cache[ ip ] = get_whois( ip )
|
58
|
+
end
|
59
|
+
|
60
|
+
def geodb_key( ip )
|
61
|
+
ip2 = IPAddr.new( ip )
|
62
|
+
return ip2.hton if ip2.ipv6?
|
63
|
+
|
64
|
+
"\0\0\0\0\0\0\0\0\0\0\0\0#{ip2.hton}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_cc( ip )
|
68
|
+
if @db.nil?
|
69
|
+
@db = BDB::Btree.open(
|
70
|
+
GEODB_FILE, nil, BDB::RDONLY, 0o0644,
|
71
|
+
'set_pagesize' => 1024, 'set_cachesize' => [ 0, 32 * 1024, 0 ]
|
72
|
+
)
|
73
|
+
end
|
74
|
+
@db.cursor.set_range( geodb_key( ip ) )[ 1 ][ 0 .. 1 ]
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_cached_cc( ip )
|
78
|
+
if @cc_cache.nil?
|
79
|
+
get_cc( ip )
|
80
|
+
else
|
81
|
+
get_cached_whois( ip )
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def load_json( filename )
|
86
|
+
result = {}
|
87
|
+
if File.exist?( filename )
|
88
|
+
raw = File.read( filename )
|
89
|
+
result = JSON.parse( raw )
|
90
|
+
end
|
91
|
+
result
|
92
|
+
end
|
93
|
+
|
94
|
+
def load_cache
|
95
|
+
@dns_cache = load_json( DNS_CACHE_FILE )
|
96
|
+
@cc_cache =
|
97
|
+
if File.exist?( GEODB_FILE )
|
98
|
+
require 'bdb'
|
99
|
+
nil
|
100
|
+
else
|
101
|
+
load_json( CC_CACHE_FILE )
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def save_cache
|
106
|
+
File.write( DNS_CACHE_FILE, "#{JSON.dump( @dns_cache )}\n" )
|
107
|
+
return if @cc_cache.nil?
|
108
|
+
|
109
|
+
File.write( CC_CACHE_FILE, "#{JSON.dump( @cc_cache )}\n" )
|
110
|
+
end
|
111
|
+
|
112
|
+
@db = nil
|
113
|
+
|
114
|
+
filter_cc = nil
|
115
|
+
filter_port = 0
|
116
|
+
until ARGV.empty?
|
117
|
+
option = ARGV.shift
|
118
|
+
case option
|
119
|
+
when 'test'
|
120
|
+
ip = ARGV.shift
|
121
|
+
@dns_cache = {}
|
122
|
+
@cc_cache = {}
|
123
|
+
p get_dns( ip )
|
124
|
+
if File.exist?( GEODB_FILE )
|
125
|
+
require 'bdb'
|
126
|
+
p get_cc( ip )
|
127
|
+
else
|
128
|
+
p get_whois( ip )
|
129
|
+
end
|
130
|
+
exit 0
|
131
|
+
when /^[0-9]+$/
|
132
|
+
filter_port = option.to_i
|
133
|
+
when /^[a-z][a-z]$/
|
134
|
+
filter_cc = option
|
135
|
+
else
|
136
|
+
warn "Fehler #{option}"
|
137
|
+
exit 65
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
load_cache
|
142
|
+
list = []
|
143
|
+
raw = `blacklistctl dump -b -n -w`
|
144
|
+
# pp raw
|
145
|
+
raw.split( "\n" ).each do |line|
|
146
|
+
address_port, state, _nfail, access = line.split( "\t", 4 )
|
147
|
+
list.push( [ access, address_port, state ] )
|
148
|
+
end
|
149
|
+
list.sort.each do |row|
|
150
|
+
access, address_port, state = row
|
151
|
+
# p [ address_port, access ]
|
152
|
+
address_port.strip!
|
153
|
+
pair = address_port.split( '/' )
|
154
|
+
port = pair.last.split( ':' ).last.to_i
|
155
|
+
next if !filter_port.zero? && ( port != filter_port )
|
156
|
+
|
157
|
+
ip = pair.first.strip
|
158
|
+
cc = get_cached_cc( ip )
|
159
|
+
next if !filter_cc.nil? && ( cc != filter_cc )
|
160
|
+
|
161
|
+
dns = get_cached_dns( ip )
|
162
|
+
white =
|
163
|
+
case state
|
164
|
+
when 'OK'
|
165
|
+
''
|
166
|
+
else
|
167
|
+
'OK/'
|
168
|
+
end
|
169
|
+
puts "#{address_port}\t#{access}\t#{white}#{cc}\t#{dns}"
|
170
|
+
end
|
171
|
+
save_cache
|
172
|
+
|
173
|
+
exit 0
|
174
|
+
# eof
|
data/bin/geodb-lookup.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
|
3
|
+
require 'ipaddr'
|
4
|
+
require 'bdb'
|
5
|
+
|
6
|
+
# pkg install databases/ruby-bdb net/webalizer-geodb
|
7
|
+
GEODB_FILE = '/usr/local/share/geolizer/GeoDB.dat'.freeze
|
8
|
+
|
9
|
+
def geodb_key( ip )
|
10
|
+
ip2 = IPAddr.new( ip )
|
11
|
+
return ip2.hton if ip2.ipv6?
|
12
|
+
|
13
|
+
"\0\0\0\0\0\0\0\0\0\0\0\0#{ip2.hton}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_cc( ip )
|
17
|
+
if @db.nil?
|
18
|
+
@db = BDB::Btree.open(
|
19
|
+
GEODB_FILE, nil, BDB::RDONLY, 0o0644,
|
20
|
+
'set_pagesize' => 1024, 'set_cachesize' => [ 0, 32 * 1024, 0 ]
|
21
|
+
)
|
22
|
+
end
|
23
|
+
@db.cursor.set_range( geodb_key( ip ) )[ 1 ][ 0 .. 1 ]
|
24
|
+
end
|
25
|
+
|
26
|
+
@db = nil
|
27
|
+
|
28
|
+
ARGV.each do |ip|
|
29
|
+
cc = get_cc( ip )
|
30
|
+
puts "#{ip}\t#{cc}"
|
31
|
+
end
|
32
|
+
|
33
|
+
exit 0
|
34
|
+
# eof
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blocklistshow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dirk Meyer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Display of data from blocklistd on FreeBSD with country codes and reverse
|
14
|
+
DNS.
|
15
|
+
email:
|
16
|
+
executables:
|
17
|
+
- blocklist.rb
|
18
|
+
- geodb-lookup.rb
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files:
|
21
|
+
- LICENSE.txt
|
22
|
+
- README.md
|
23
|
+
files:
|
24
|
+
- ".rubocop.yml"
|
25
|
+
- CHANGELOG.md
|
26
|
+
- Gemfile
|
27
|
+
- LICENSE.txt
|
28
|
+
- Makefile
|
29
|
+
- README.md
|
30
|
+
- bin/blocklist.rb
|
31
|
+
- bin/geodb-lookup.rb
|
32
|
+
homepage: https://rubygems.org/gems/blocklistshow
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata: {}
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '2.4'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubygems_version: 3.0.8
|
52
|
+
signing_key:
|
53
|
+
specification_version: 4
|
54
|
+
summary: show blocklistd data
|
55
|
+
test_files: []
|