Class: Arbor::Atlas
- Inherits:
-
Object
- Object
- Arbor::Atlas
- Defined in:
- lib/arbor/atlas.rb,
lib/arbor/atlas/version.rb
Constant Summary collapse
- VERSION =
"0.1.2"
- @@baseurl =
"https://atlas.arbor.net"
Instance Attribute Summary collapse
-
#cookie ⇒ Object
readonly
Returns the value of attribute cookie.
Instance Method Summary collapse
- #_get(path, params) ⇒ Object
- #_post(path, params) ⇒ Object
-
#initialize(username, password) ⇒ Atlas
constructor
A new instance of Atlas.
- #lookup(item) ⇒ Object
- #lookup_asn(asn) ⇒ Object
- #lookup_cc(cc) ⇒ Object
- #lookup_cidr(cidr) ⇒ Object
- #lookup_cve(cve) ⇒ Object
- #lookup_ip(ip) ⇒ Object
- #lookup_service(port) ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Atlas
Returns a new instance of Atlas.
12 13 14 15 16 |
# File 'lib/arbor/atlas.rb', line 12 def initialize(username, password) params = {'name' => username, 'password' => password, 'referer' => @@baseurl+"/"} @cookie = nil _post("user/login",params) end |
Instance Attribute Details
#cookie ⇒ Object (readonly)
Returns the value of attribute cookie.
11 12 13 |
# File 'lib/arbor/atlas.rb', line 11 def @cookie end |
Instance Method Details
#_get(path, params) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/arbor/atlas.rb', line 37 def _get(path, params) url = URI.parse "#{@@baseurl}/#{path}" data = params.map { |k,v| "#{k}=#{v}".gsub(/([^ a-zA-Z0-9_.-=]+)/) do '%' + $1.unpack('H2' * $1.bytesize).join('%').upcase end.tr(' ', '+') }.join("&") request = Net::HTTP::Get.new(url.path+"?"+data) request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} arbor-atlas rubygem v#{Arbor::Atlas::VERSION}") request.add_field("Referer", @@baseurl) request.add_field("Cookie", @cookie) if @cookie http = Net::HTTP.new(url.host, url.port) if url.scheme == 'https' http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.verify_depth = 5 end resp = http.request(request) @cookie = resp.header["set-cookie"] if resp.header["set-cookie"] resp.body end |
#_post(path, params) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/arbor/atlas.rb', line 18 def _post(path, params) url = URI.parse "#{@@baseurl}/#{path}" request = Net::HTTP::Post.new(url.path) request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} arbor-atlas rubygem v#{Arbor::Atlas::VERSION}") request.add_field("Referer", @@baseurl) request.add_field("Cookie", @cookie) if @cookie request.set_form_data(params) http = Net::HTTP.new(url.host, url.port) if url.scheme == 'https' http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.verify_depth = 5 end resp = http.request(request) @cookie = resp.header["set-cookie"] if resp.header["set-cookie"] resp.body end |
#lookup(item) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/arbor/atlas.rb', line 90 def lookup(item) if item =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\/\d{1,2})?$/ lookup_ip(item) elsif item =~ /^(AS)?\d{1,7}$/i lookup_asn(item) elsif item =~ /^CVE\-\d{4}-\d+$/i lookup_cve(item) elsif item =~ /^\w{2}$/i lookup_cc(item) elsif item =~ /^(UDP|TCP)\/\d{1,5}$/i lookup_service(item) else raise ArgumentError, "unknown query type for item: #{item}" end end |
#lookup_asn(asn) ⇒ Object
65 66 67 68 69 |
# File 'lib/arbor/atlas.rb', line 65 def lookup_asn(asn) asn = asn.gsub(/[^0-9]/,'') doc = _get("asn/#{asn}",{'out'=>'xml'}) Crack::XML.parse(doc) end |
#lookup_cc(cc) ⇒ Object
76 77 78 79 |
# File 'lib/arbor/atlas.rb', line 76 def lookup_cc(cc) doc = _get("cc/#{cc.upcase}",{'out'=>'xml'}) Crack::XML.parse(doc) end |
#lookup_cidr(cidr) ⇒ Object
81 82 83 |
# File 'lib/arbor/atlas.rb', line 81 def lookup_cidr(cidr) lookup_ip(cidr) end |
#lookup_cve(cve) ⇒ Object
71 72 73 74 |
# File 'lib/arbor/atlas.rb', line 71 def lookup_cve(cve) doc = _get("vuln/#{cve.upcase}",{'out'=>'xml'}) Crack::XML.parse(doc) end |
#lookup_ip(ip) ⇒ Object
60 61 62 63 |
# File 'lib/arbor/atlas.rb', line 60 def lookup_ip(ip) doc = _get("ip/#{ip}",{'out'=>'xml'}) Crack::XML.parse(doc) end |
#lookup_service(port) ⇒ Object
85 86 87 88 |
# File 'lib/arbor/atlas.rb', line 85 def lookup_service(port) doc = _get("service/#{port.downcase}",{'out'=>'xml'}) Crack::XML.parse(doc) end |