lib/scanner/generic.rb in yawast-0.5.0.beta1 vs lib/scanner/generic.rb in yawast-0.5.0.beta2

- old
+ new

@@ -1,6 +1,7 @@ require 'ipaddr_extensions' +require 'json' module Yawast module Scanner class Generic def self.server_info(uri, options) @@ -22,12 +23,16 @@ # if address is private, force internal SSL mode, don't show links if IPAddr.new(ip.address.to_s, Socket::AF_INET).private? options.internalssl = true else - puts "\t\t\t\thttps://www.shodan.io/host/#{ip.address}" - puts "\t\t\t\thttps://censys.io/ipv4/#{ip.address}" + #show network info + get_network_info ip + get_network_location_info ip + + puts "\t\t\thttps://www.shodan.io/host/#{ip.address}" + puts "\t\t\thttps://censys.io/ipv4/#{ip.address}" end end end aaaa = resv.getresources(uri.host, Resolv::DNS::Resource::IN::AAAA) @@ -43,11 +48,15 @@ # if address is private, force internal SSL mode, don't show links if IPAddr.new(ip.address.to_s, Socket::AF_INET6).private? options.internalssl = true else - puts "\t\t\t\thttps://www.shodan.io/host/#{ip.address.to_s.downcase}" + #show network info + get_network_info ip + get_network_location_info ip + + puts "\t\t\thttps://www.shodan.io/host/#{ip.address.to_s.downcase}" end end end txt = resv.getresources(uri.host, Resolv::DNS::Resource::IN::TXT) @@ -74,9 +83,32 @@ puts rescue => e Yawast::Utilities.puts_error "Error getting basic information: #{e.message}" raise + end + end + + def self.get_network_info(ip) + begin + network_info = JSON.parse(Net::HTTP.get(URI("https://api.iptoasn.com/v1/as/ip/#{ip.address}"))) + + Yawast::Utilities.puts_info "\t\t\t#{network_info['as_country_code']} - #{network_info['as_description']}" + rescue => e + Yawast::Utilities.puts_error "Error getting network information: #{e.message}" + end + end + + def self.get_network_location_info(ip) + begin + info = JSON.parse(Net::HTTP.get(URI("https://freegeoip.net/json/#{ip.address}"))) + location = [info['city'], info['region_name'], info['country_code']].reject { |c| c.empty? }.join(', ') + + if location != nil && !location.empty? + Yawast::Utilities.puts_info "\t\t\t#{location}" + end + rescue => e + Yawast::Utilities.puts_error "Error getting location information: #{e.message}" end end def self.head_info(head, uri) begin