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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 864264dbb2474e4076ce50d6430d47c40894d007
4
- data.tar.gz: d7188776809a8ddf78cb16824899867370c4a18f
3
+ metadata.gz: 8f524665f5d4131c5e6d0696462bc4aaec71efd4
4
+ data.tar.gz: 645eafa5e1b6c66fc91f17199c6780a7004083af
5
5
  SHA512:
6
- metadata.gz: 13a04b21878da770de924a93a9129cbcef86924b5e1983fef2611cc4bf8300207463802a556037191e44a63c8c2256f558cb85ec89115af223b7915e4abfa5c8
7
- data.tar.gz: 0b9f7ea870cde1b98410bbbb3b25119fa07f933a68fc3f3cce2c00547b932e7e8c5d0284170c3f939efca22a625f126ecc2dcc58e895cf6d3058d90b8249e3e0
6
+ metadata.gz: b58da993c169a7b52dc86947d1a78af1e9f1614f9027129d75cddf7442c60f0ebf88571ba5431c7a8bf0590c88f80bc2713389d4a4877e948cba0929b06fb555
7
+ data.tar.gz: 56dbfb6e4caa5c638d6c98ba7714565c771bea63e5df051208e609f3f1add2992bc373cd9e3f075e2b9ad957b21990467f6db69a6b7c280db9d61e7ce619e2d8
data/Rakefile CHANGED
@@ -1,2 +1 @@
1
- require "bundler/gem_tasks"
2
-
1
+ require 'bundler/gem_tasks'
data/bin/unspam CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'unspam'
3
3
 
4
-
5
4
  Unspam::CLI.start
data/lib/unspam.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "unspam/version"
2
- require "unspam/cli"
1
+ require 'unspam/version'
2
+ require 'unspam/cli'
3
3
 
4
4
  module Unspam
5
5
  end
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
- desc "ripe ASN MSG", "bla"
8
+ map 'NETS' => :nets
9
+ map 'ripe' => :nets
10
+ map 'RIPE' => :nets
8
11
 
9
- def ripe(asn, msg = nil)
10
- response = HTTParty.get "https://stat.ripe.net/data/announced-prefixes/data.json?resource=#{asn}&min_peers_seeing=1"
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
- result = JSON.parse(response.body)
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
- result['data']['prefixes'].map{ |h| h['prefix']}.sort.each do |prefix|
15
- printf("%-25s%5s\n", prefix, msg)
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
@@ -1,3 +1,3 @@
1
1
  module Unspam
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
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 = "unspam"
7
+ spec.name = 'unspam'
8
8
  spec.version = Unspam::VERSION
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"
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 = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency "thor"
22
- spec.add_dependency "httparty"
21
+ spec.add_dependency 'thor'
22
+ spec.add_dependency 'httparty'
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.6"
25
- spec.add_development_dependency "rake"
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake'
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unspam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roland Moriz