unspam 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -2
- data/bin/unspam +0 -1
- data/lib/unspam.rb +2 -2
- data/lib/unspam/cli.rb +35 -6
- data/lib/unspam/version.rb +1 -1
- data/unspam.gemspec +12 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f524665f5d4131c5e6d0696462bc4aaec71efd4
|
4
|
+
data.tar.gz: 645eafa5e1b6c66fc91f17199c6780a7004083af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b58da993c169a7b52dc86947d1a78af1e9f1614f9027129d75cddf7442c60f0ebf88571ba5431c7a8bf0590c88f80bc2713389d4a4877e948cba0929b06fb555
|
7
|
+
data.tar.gz: 56dbfb6e4caa5c638d6c98ba7714565c771bea63e5df051208e609f3f1add2992bc373cd9e3f075e2b9ad957b21990467f6db69a6b7c280db9d61e7ce619e2d8
|
data/Rakefile
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/unspam
CHANGED
data/lib/unspam.rb
CHANGED
data/lib/unspam/cli.rb
CHANGED
@@ -1,20 +1,49 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'json'
|
3
3
|
require 'httparty'
|
4
|
+
require 'ipaddr'
|
4
5
|
|
5
6
|
module Unspam
|
6
7
|
class CLI < Thor
|
7
|
-
|
8
|
+
map 'NETS' => :nets
|
9
|
+
map 'ripe' => :nets
|
10
|
+
map 'RIPE' => :nets
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
desc 'nets ASN/IP [MESSAGE]', 'ASN or IP address. MESSAGE is optional'
|
13
|
+
def nets(asn_or_ip, msg = nil)
|
14
|
+
@msg = msg
|
11
15
|
|
12
|
-
|
16
|
+
if asn_or_ip =~ /^AS|^[^\.]$/
|
17
|
+
lookup_by_asn(asn_or_ip)
|
18
|
+
else
|
19
|
+
lookup_by_ip(asn_or_ip)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
no_commands do
|
24
|
+
def lookup_by_ip(ip)
|
25
|
+
response = HTTParty.get "https://stat.ripe.net/data/searchcomplete/data.json?resource=#{ip}"
|
26
|
+
result = JSON.parse(response.body)
|
27
|
+
|
28
|
+
as = []
|
13
29
|
|
14
|
-
|
15
|
-
|
30
|
+
result['data']['categories'].each do |cat|
|
31
|
+
as += cat['suggestions'].map { |s| s['value'] }
|
32
|
+
end
|
33
|
+
|
34
|
+
as.select { |v| v =~ /^AS/ }.each do |asn|
|
35
|
+
lookup_by_asn(asn)
|
36
|
+
end
|
16
37
|
end
|
17
38
|
|
39
|
+
def lookup_by_asn(asn)
|
40
|
+
response = HTTParty.get "https://stat.ripe.net/data/announced-prefixes/data.json?resource=#{asn}&min_peers_seeing=1"
|
41
|
+
result = JSON.parse(response.body)
|
42
|
+
|
43
|
+
result['data']['prefixes'].map { |h| h['prefix'] }.sort.each do |prefix|
|
44
|
+
printf("%-25s%5s\n", prefix, @msg)
|
45
|
+
end
|
46
|
+
end
|
18
47
|
end
|
19
48
|
end
|
20
49
|
end
|
data/lib/unspam/version.rb
CHANGED
data/unspam.gemspec
CHANGED
@@ -4,23 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'unspam/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'unspam'
|
8
8
|
spec.version = Unspam::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary = %q
|
12
|
-
spec.description = %q
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Roland Moriz']
|
10
|
+
spec.email = ['roland@moriz.de']
|
11
|
+
spec.summary = %q(returns IP prefixes by ASN.)
|
12
|
+
spec.description = %q(returns IP prefixes by ASN.)
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency
|
22
|
-
spec.add_dependency
|
21
|
+
spec.add_dependency 'thor'
|
22
|
+
spec.add_dependency 'httparty'
|
23
23
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
26
|
end
|