Class: SearchApnic::Search
- Inherits:
-
Object
- Object
- SearchApnic::Search
- Defined in:
- lib/search_apnic/search.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#by_country(country, protocol_version: 'ipv4') ⇒ Object
File Format ftp.apnic.net/apnic/stats/apnic/README.TXT.
- #header ⇒ Object
- #include?(ip) ⇒ Boolean
- #print ⇒ Object
- #records ⇒ Object
- #summary ⇒ Object
Class Method Details
.countries ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/search_apnic/search.rb', line 47 def self.countries %w{ AP AS AU BD BN BR BT CA CK CN CO DE ES FJ FM FR GB GU HK ID IN IO IR JP KE KH KI KP KR LA LK MH MM MN MO MP MU MV MY NC NF NL NP NR NU NZ PF PG PH PK PW SA SB SC SE SG TH TK TL TO TR TV TW US VN VU WF WS ZA } end |
Instance Method Details
#by_country(country, protocol_version: 'ipv4') ⇒ Object
File Format ftp.apnic.net/apnic/stats/apnic/README.TXT
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/search_apnic/search.rb', line 6 def by_country(country, protocol_version: 'ipv4') ::File.foreach(SearchApnic::File.new.get_path) do |l| next if l[0] == "#" # Comment Line row = l.strip.split("|") unless header set_header(row) next end if(row[5] == 'summary') add_summary(row) next end record = parse_record(row) next if record[:type] == 'asn' # Autonomous System number next if record[:cc] != country next if record[:type] != protocol_version # ipv4 or ipv6 add_record record end self end |
#header ⇒ Object
80 81 82 |
# File 'lib/search_apnic/search.rb', line 80 def header @header end |
#include?(ip) ⇒ Boolean
37 38 39 40 41 42 43 44 45 |
# File 'lib/search_apnic/search.rb', line 37 def include?(ip) search_first_number = ip.split(".").first records.select{|ip_and_mask| search_first_number == ip_and_mask.split(".").first}.each do |ip_and_mask| if IPAddr.new(ip_and_mask).include? ip return ip_and_mask end end return false end |
#print ⇒ Object
31 32 33 34 35 |
# File 'lib/search_apnic/search.rb', line 31 def print records.each do|l| puts l end end |
#records ⇒ Object
72 73 74 |
# File 'lib/search_apnic/search.rb', line 72 def records @records end |
#summary ⇒ Object
76 77 78 |
# File 'lib/search_apnic/search.rb', line 76 def summary @summary end |