cymruwhois 0.0.2
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.
- data/History.txt +4 -0
- data/README.rdoc +60 -0
- data/cymruwhois.gemspec +18 -0
- data/lib/cymruwhois.rb +86 -0
- metadata +73 -0
data/History.txt
ADDED
data/README.rdoc
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
|
|
2
|
+
== DESCRIPTION:
|
|
3
|
+
|
|
4
|
+
cymruwhois is a simple Ruby module that utilizes Team Cymru's IP to ASN Mapping
|
|
5
|
+
via DNS queries. The module was conceived as an IP geolocation alternative to GeoIP.
|
|
6
|
+
|
|
7
|
+
Kindly take note of Team Cymru's "Special Notice" for bulk queries at the
|
|
8
|
+
top of the page: http://www.team-cymru.org/Services/ip-to-asn.html
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
== FEATURES/PROBLEMS:
|
|
12
|
+
|
|
13
|
+
The module does not include the Bogon, and Malware Hash registry services
|
|
14
|
+
of Team Cymru.
|
|
15
|
+
|
|
16
|
+
== SYNOPSIS:
|
|
17
|
+
|
|
18
|
+
require 'cymruwhois'
|
|
19
|
+
|
|
20
|
+
c = Cymru::IPAddress.new
|
|
21
|
+
c.whois("72.4.120.124")
|
|
22
|
+
> ["27357", "72.4.112.0/20", "US", "ARIN", "2008-10-09", "RACKSPACE - RACKSPACE HOSTING"]
|
|
23
|
+
c.country
|
|
24
|
+
> "US"
|
|
25
|
+
|
|
26
|
+
as = Cymru::ASNumber.new
|
|
27
|
+
as.whois("27357")
|
|
28
|
+
> ["27357", "US", "ARIN", "2003-02-20", "RACKSPACE - RACKSPACE HOSTING"]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
== REQUIREMENTS:
|
|
32
|
+
|
|
33
|
+
== INSTALL:
|
|
34
|
+
|
|
35
|
+
sudo gem install cymruwhois
|
|
36
|
+
|
|
37
|
+
== LICENSE:
|
|
38
|
+
|
|
39
|
+
(The MIT License)
|
|
40
|
+
|
|
41
|
+
Copyright (c) 2011 Jun C. Valdez
|
|
42
|
+
|
|
43
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
44
|
+
a copy of this software and associated documentation files (the
|
|
45
|
+
'Software'), to deal in the Software without restriction, including
|
|
46
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
47
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
48
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
49
|
+
the following conditions:
|
|
50
|
+
|
|
51
|
+
The above copyright notice and this permission notice shall be
|
|
52
|
+
included in all copies or substantial portions of the Software.
|
|
53
|
+
|
|
54
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
55
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
56
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
57
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
58
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
59
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
60
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/cymruwhois.gemspec
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require "rubygems"
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = "cymruwhois"
|
|
5
|
+
s.version = "0.0.2"
|
|
6
|
+
s.license = "MIT"
|
|
7
|
+
s.author = "Jun C. Valdez"
|
|
8
|
+
s.email = "rubygems@sploitlabs.com"
|
|
9
|
+
s.files = ["lib/cymruwhois.rb","README.rdoc", "History.txt", "cymruwhois.gemspec"]
|
|
10
|
+
s.summary = "cymru is a module that utilizes Team Cymru's IP to ASN Mapping"
|
|
11
|
+
s.description = %q{cymruwhois is a simple Ruby module that utilizes Team Cymru's IP to ASN Mapping
|
|
12
|
+
via DNS queries. The module was conceived as an IP geolocation alternative to GeoIP.
|
|
13
|
+
|
|
14
|
+
Kindly take note of Team Cymru's "Special Notice" for bulk queries at the
|
|
15
|
+
top of the page: http://www.team-cymru.org/Services/ip-to-asn.html}
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
data/lib/cymruwhois.rb
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2011 Jun C. Valdez
|
|
4
|
+
# Code is distributed under the terms of an MIT style license
|
|
5
|
+
# http://www.opensource.org/licenses/mit-license
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
require 'resolv'
|
|
9
|
+
require 'ipaddr'
|
|
10
|
+
|
|
11
|
+
module Cymru
|
|
12
|
+
|
|
13
|
+
module DNSquery
|
|
14
|
+
def intxt(name)
|
|
15
|
+
dns = Resolv::DNS.new
|
|
16
|
+
ans = dns.getresource(name, Resolv::DNS::Resource::IN::TXT)
|
|
17
|
+
arr = ans.data.split('|').map {|e| e.upcase.strip}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class IPAddress
|
|
22
|
+
include DNSquery
|
|
23
|
+
private :intxt
|
|
24
|
+
|
|
25
|
+
attr_reader :asnum, :cidr, :country, :registry, :allocdate, :asname
|
|
26
|
+
|
|
27
|
+
ORIGIN = "origin.asn.cymru.com"
|
|
28
|
+
ORIGIN6 = "origin6.asn.cymru.com"
|
|
29
|
+
BOGON = "bogons.cymru.com"
|
|
30
|
+
|
|
31
|
+
def initialize
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def whois(addr)
|
|
35
|
+
ip = IPAddr.new(addr)
|
|
36
|
+
if ip.ipv4?
|
|
37
|
+
revdns = ip.reverse.sub("in-addr.arpa", ORIGIN)
|
|
38
|
+
elsif ip.ipv6?
|
|
39
|
+
revdns = ip.reverse.sub("ip6.arpa", ORIGIN6)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
ansip = intxt(revdns)
|
|
43
|
+
@asnum = ansip[0]
|
|
44
|
+
@cidr = ansip[1]
|
|
45
|
+
@country = ansip[2]
|
|
46
|
+
@registry = ansip[3]
|
|
47
|
+
@allocdate = ansip[4]
|
|
48
|
+
|
|
49
|
+
ansasnum = Cymru::ASNumber.new
|
|
50
|
+
ansasnum.whois(@asnum)
|
|
51
|
+
@asname = ansasnum.asname
|
|
52
|
+
|
|
53
|
+
ansip << @asname
|
|
54
|
+
end
|
|
55
|
+
alias :lookup :whois
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
class ASNumber
|
|
60
|
+
include DNSquery
|
|
61
|
+
private :intxt
|
|
62
|
+
|
|
63
|
+
attr_reader :country, :registry, :allocdate, :asname
|
|
64
|
+
|
|
65
|
+
ASN = ".asn.cymru.com"
|
|
66
|
+
|
|
67
|
+
def initialize
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def whois(asn)
|
|
71
|
+
@asn = "AS" + asn + ASN
|
|
72
|
+
|
|
73
|
+
ans = intxt(@asn)
|
|
74
|
+
@country = ans[1]
|
|
75
|
+
@registry = ans[2]
|
|
76
|
+
@allocdate = ans[3]
|
|
77
|
+
@asname = ans[4]
|
|
78
|
+
|
|
79
|
+
return ans
|
|
80
|
+
end
|
|
81
|
+
alias :lookup :whois
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
|
metadata
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cymruwhois
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 27
|
|
5
|
+
prerelease:
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 2
|
|
10
|
+
version: 0.0.2
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Jun C. Valdez
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2011-05-30 00:00:00 Z
|
|
19
|
+
dependencies: []
|
|
20
|
+
|
|
21
|
+
description: |-
|
|
22
|
+
cymruwhois is a simple Ruby module that utilizes Team Cymru's IP to ASN Mapping
|
|
23
|
+
via DNS queries. The module was conceived as an IP geolocation alternative to GeoIP.
|
|
24
|
+
|
|
25
|
+
Kindly take note of Team Cymru's "Special Notice" for bulk queries at the
|
|
26
|
+
top of the page: http://www.team-cymru.org/Services/ip-to-asn.html
|
|
27
|
+
email: rubygems@sploitlabs.com
|
|
28
|
+
executables: []
|
|
29
|
+
|
|
30
|
+
extensions: []
|
|
31
|
+
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
|
|
34
|
+
files:
|
|
35
|
+
- lib/cymruwhois.rb
|
|
36
|
+
- README.rdoc
|
|
37
|
+
- History.txt
|
|
38
|
+
- cymruwhois.gemspec
|
|
39
|
+
homepage:
|
|
40
|
+
licenses:
|
|
41
|
+
- MIT
|
|
42
|
+
post_install_message:
|
|
43
|
+
rdoc_options: []
|
|
44
|
+
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
none: false
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
hash: 3
|
|
53
|
+
segments:
|
|
54
|
+
- 0
|
|
55
|
+
version: "0"
|
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
hash: 3
|
|
62
|
+
segments:
|
|
63
|
+
- 0
|
|
64
|
+
version: "0"
|
|
65
|
+
requirements: []
|
|
66
|
+
|
|
67
|
+
rubyforge_project:
|
|
68
|
+
rubygems_version: 1.8.4
|
|
69
|
+
signing_key:
|
|
70
|
+
specification_version: 3
|
|
71
|
+
summary: cymru is a module that utilizes Team Cymru's IP to ASN Mapping
|
|
72
|
+
test_files: []
|
|
73
|
+
|