wmap 2.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +141 -0
- data/LICENSE.txt +15 -0
- data/README.rdoc +98 -0
- data/TODO +13 -0
- data/bin/deprime +21 -0
- data/bin/distrust +38 -0
- data/bin/googleBot +23 -0
- data/bin/prime +21 -0
- data/bin/refresh +26 -0
- data/bin/run_tests +16 -0
- data/bin/spiderBot +26 -0
- data/bin/trust +38 -0
- data/bin/updateAll +57 -0
- data/bin/wadd +25 -0
- data/bin/wadds +26 -0
- data/bin/wcheck +28 -0
- data/bin/wdel +25 -0
- data/bin/wdump +21 -0
- data/bin/wmap +151 -0
- data/bin/wscan +32 -0
- data/data/cidrs +2 -0
- data/data/deactivated_sites +1 -0
- data/data/domains +2 -0
- data/data/hosts +1 -0
- data/data/prime_hosts +1 -0
- data/data/sites +2 -0
- data/data/sub_domains +2 -0
- data/demos/bruter.rb +27 -0
- data/demos/dns_brutes.rb +28 -0
- data/demos/filter_cidr.rb +18 -0
- data/demos/filter_crawls.rb +5 -0
- data/demos/filter_domain.rb +25 -0
- data/demos/filter_geoip.rb +26 -0
- data/demos/filter_known_services.rb +59 -0
- data/demos/filter_netinfo.rb +23 -0
- data/demos/filter_prime.rb +25 -0
- data/demos/filter_profiler.rb +3 -0
- data/demos/filter_redirection.rb +19 -0
- data/demos/filter_site.rb +40 -0
- data/demos/filter_siteip.rb +31 -0
- data/demos/filter_status.rb +17 -0
- data/demos/filter_timestamp.rb +23 -0
- data/demos/filter_url.rb +19 -0
- data/demos/new_fnd.rb +66 -0
- data/demos/nmap_parser.pl +138 -0
- data/demos/site_format.rb +18 -0
- data/demos/whois_domain.rb +78 -0
- data/dicts/GeoIP.dat +0 -0
- data/dicts/GeoIPASNum.dat +0 -0
- data/dicts/GeoLiteCity.dat +0 -0
- data/dicts/ccsld.txt +2646 -0
- data/dicts/cctld.txt +243 -0
- data/dicts/gtld.txt +25 -0
- data/dicts/hostnames-dict.big +1402 -0
- data/dicts/hostnames-dict.txt +101 -0
- data/lib/wmap/cidr_tracker.rb +327 -0
- data/lib/wmap/dns_bruter.rb +308 -0
- data/lib/wmap/domain_tracker/sub_domain.rb +142 -0
- data/lib/wmap/domain_tracker.rb +342 -0
- data/lib/wmap/geoip_tracker.rb +72 -0
- data/lib/wmap/google_search_scraper.rb +177 -0
- data/lib/wmap/host_tracker/primary_host.rb +130 -0
- data/lib/wmap/host_tracker.rb +550 -0
- data/lib/wmap/network_profiler.rb +144 -0
- data/lib/wmap/port_scanner.rb +208 -0
- data/lib/wmap/site_tracker/deactivated_site.rb +85 -0
- data/lib/wmap/site_tracker.rb +937 -0
- data/lib/wmap/url_checker.rb +314 -0
- data/lib/wmap/url_crawler.rb +381 -0
- data/lib/wmap/utils/domain_root.rb +184 -0
- data/lib/wmap/utils/logger.rb +53 -0
- data/lib/wmap/utils/url_magic.rb +343 -0
- data/lib/wmap/utils/utils.rb +333 -0
- data/lib/wmap/whois.rb +76 -0
- data/lib/wmap.rb +227 -0
- data/logs/wmap.log +17 -0
- data/ruby_whois_patches/base_cocca2.rb +149 -0
- data/ruby_whois_patches/kero.yachay.pe.rb +120 -0
- data/ruby_whois_patches/whois.PublicDomainRegistry.com.rb +124 -0
- data/ruby_whois_patches/whois.above.com.rb +61 -0
- data/ruby_whois_patches/whois.adamsnames.tc.rb +107 -0
- data/ruby_whois_patches/whois.aeda.net.ae.rb +105 -0
- data/ruby_whois_patches/whois.ai.rb +112 -0
- data/ruby_whois_patches/whois.arnes.si.rb +121 -0
- data/ruby_whois_patches/whois.ascio.com.rb +91 -0
- data/ruby_whois_patches/whois.cnnic.cn.rb +123 -0
- data/ruby_whois_patches/whois.corporatedomains.com.rb +67 -0
- data/ruby_whois_patches/whois.crsnic.net.rb +108 -0
- data/ruby_whois_patches/whois.denic.de.rb +174 -0
- data/ruby_whois_patches/whois.dk-hostmaster.dk.rb +120 -0
- data/ruby_whois_patches/whois.dns.be.rb +134 -0
- data/ruby_whois_patches/whois.dns.lu.rb +129 -0
- data/ruby_whois_patches/whois.dns.pl.rb +150 -0
- data/ruby_whois_patches/whois.dns.pt.rb +119 -0
- data/ruby_whois_patches/whois.domain.kg.rb +126 -0
- data/ruby_whois_patches/whois.domainregistry.my.rb +123 -0
- data/ruby_whois_patches/whois.domreg.lt.rb +110 -0
- data/ruby_whois_patches/whois.dot.tk.rb +140 -0
- data/ruby_whois_patches/whois.hkirc.hk.rb +121 -0
- data/ruby_whois_patches/whois.isnic.is.rb +130 -0
- data/ruby_whois_patches/whois.je.rb +119 -0
- data/ruby_whois_patches/whois.jprs.jp.rb +137 -0
- data/ruby_whois_patches/whois.kenic.or.ke.rb +140 -0
- data/ruby_whois_patches/whois.markmonitor.com.rb +118 -0
- data/ruby_whois_patches/whois.melbourneit.com.rb +58 -0
- data/ruby_whois_patches/whois.nic.as.rb +96 -0
- data/ruby_whois_patches/whois.nic.at.rb +109 -0
- data/ruby_whois_patches/whois.nic.ch.rb +141 -0
- data/ruby_whois_patches/whois.nic.cl.rb +117 -0
- data/ruby_whois_patches/whois.nic.ec.rb +157 -0
- data/ruby_whois_patches/whois.nic.im.rb +120 -0
- data/ruby_whois_patches/whois.nic.it.rb +170 -0
- data/ruby_whois_patches/whois.nic.lv.rb +116 -0
- data/ruby_whois_patches/whois.nic.ly.rb +127 -0
- data/ruby_whois_patches/whois.nic.mu.rb +27 -0
- data/ruby_whois_patches/whois.nic.mx.rb +123 -0
- data/ruby_whois_patches/whois.nic.net.sa.rb +111 -0
- data/ruby_whois_patches/whois.nic.or.kr.rb +101 -0
- data/ruby_whois_patches/whois.nic.tel.rb +129 -0
- data/ruby_whois_patches/whois.nic.tr.rb +133 -0
- data/ruby_whois_patches/whois.nic.us.rb +129 -0
- data/ruby_whois_patches/whois.nic.ve.rb +135 -0
- data/ruby_whois_patches/whois.norid.no.rb +127 -0
- data/ruby_whois_patches/whois.pandi.or.id.rb +118 -0
- data/ruby_whois_patches/whois.psi-usa.info.rb +63 -0
- data/ruby_whois_patches/whois.registro.br.rb +109 -0
- data/ruby_whois_patches/whois.registrygate.com.rb +55 -0
- data/ruby_whois_patches/whois.rrpproxy.net.rb +61 -0
- data/ruby_whois_patches/whois.sgnic.sg.rb +130 -0
- data/ruby_whois_patches/whois.srs.net.nz.rb +166 -0
- data/ruby_whois_patches/whois.tucows.com.rb +70 -0
- data/ruby_whois_patches/whois.twnic.net.tw.rb +133 -0
- data/settings/discovery_ports +24 -0
- data/settings/google_keywords.txt +9 -0
- data/settings/google_locator.txt +23 -0
- data/test/domain_tracker_test.rb +31 -0
- data/test/utils_test.rb +168 -0
- data/version.txt +13 -0
- data/wmap.gemspec +49 -0
- metadata +202 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
# The top 100 most common hostname prefix
|
2
|
+
www
|
3
|
+
host
|
4
|
+
mail
|
5
|
+
dummy
|
6
|
+
router
|
7
|
+
ns
|
8
|
+
ftp
|
9
|
+
gw
|
10
|
+
server
|
11
|
+
user
|
12
|
+
gateway
|
13
|
+
pc1
|
14
|
+
pc3
|
15
|
+
pc2
|
16
|
+
smtp
|
17
|
+
pc4
|
18
|
+
ns1
|
19
|
+
pc5
|
20
|
+
www2
|
21
|
+
pc6
|
22
|
+
a
|
23
|
+
ns2
|
24
|
+
broadcast
|
25
|
+
pc10
|
26
|
+
pc11
|
27
|
+
pc12
|
28
|
+
ip
|
29
|
+
proxy
|
30
|
+
pc7
|
31
|
+
pc8
|
32
|
+
gate
|
33
|
+
test
|
34
|
+
pc9
|
35
|
+
dns
|
36
|
+
news
|
37
|
+
mailhost
|
38
|
+
pc13
|
39
|
+
network
|
40
|
+
s0
|
41
|
+
pc14
|
42
|
+
home
|
43
|
+
pc15
|
44
|
+
pc16
|
45
|
+
pc18
|
46
|
+
pc17
|
47
|
+
host3
|
48
|
+
host4
|
49
|
+
pc19
|
50
|
+
pc20
|
51
|
+
cisco
|
52
|
+
host5
|
53
|
+
host1
|
54
|
+
pc22
|
55
|
+
host11
|
56
|
+
pc21
|
57
|
+
host10
|
58
|
+
host12
|
59
|
+
pc23
|
60
|
+
host13
|
61
|
+
pc24
|
62
|
+
pc25
|
63
|
+
venus
|
64
|
+
host2
|
65
|
+
host6
|
66
|
+
pc26
|
67
|
+
pc27
|
68
|
+
mars
|
69
|
+
pc28
|
70
|
+
zeus
|
71
|
+
host7
|
72
|
+
host8
|
73
|
+
host9
|
74
|
+
ppp1
|
75
|
+
pluto
|
76
|
+
host14
|
77
|
+
pc29
|
78
|
+
web
|
79
|
+
host27
|
80
|
+
jupiter
|
81
|
+
host20
|
82
|
+
admin
|
83
|
+
host15
|
84
|
+
ppp2
|
85
|
+
host22
|
86
|
+
host18
|
87
|
+
host28
|
88
|
+
host23
|
89
|
+
host25
|
90
|
+
host19
|
91
|
+
host24
|
92
|
+
host21
|
93
|
+
host26
|
94
|
+
firewall
|
95
|
+
mercury
|
96
|
+
pc30
|
97
|
+
alpha
|
98
|
+
host29
|
99
|
+
host17
|
100
|
+
ws1
|
101
|
+
ws2
|
@@ -0,0 +1,327 @@
|
|
1
|
+
#--
|
2
|
+
# Wmap
|
3
|
+
#
|
4
|
+
# A pure Ruby library for the Internet web application discovery and tracking.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2012-2015 Yang Li <yang.li@owasp.org>
|
7
|
+
#++
|
8
|
+
require "netaddr"
|
9
|
+
|
10
|
+
# Class to track host/IP to the known (trusted) network CIDR blocks
|
11
|
+
class Wmap::CidrTracker
|
12
|
+
include Wmap::Utils
|
13
|
+
|
14
|
+
attr_accessor :cidr_seeds, :verbose, :known_cidr_blks, :data_dir
|
15
|
+
|
16
|
+
# Set class default variables
|
17
|
+
def initialize (params = {})
|
18
|
+
@verbose=params.fetch(:verbose, false)
|
19
|
+
@data_dir=params.fetch(:data_dir, File.dirname(__FILE__)+'/../../data/')
|
20
|
+
@file_cidr_seeds=params.fetch(:cidr_seeds, @data_dir + 'cidrs')
|
21
|
+
@known_cidr_blks={}
|
22
|
+
@known_cidr_blks_desc_index=[]
|
23
|
+
@known_cidr_blks_asce_index=[]
|
24
|
+
File.write(@file_cidr_seeds, "") unless File.exist?(@file_cidr_seeds)
|
25
|
+
load_cidr_blks_from_file(@file_cidr_seeds)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Main worker method to retrieve known network information for a host / ip
|
29
|
+
def cidr_worker (host)
|
30
|
+
puts "Starting tracking of known CIDR information for host: #{host}" if @verbose
|
31
|
+
begin
|
32
|
+
host=host.strip.downcase
|
33
|
+
ip=host_2_ip(host)
|
34
|
+
cidr=cidr_lookup(ip)
|
35
|
+
ref=get_cidr_ref(cidr)
|
36
|
+
netname=get_cidr_netname(cidr)
|
37
|
+
# save the data
|
38
|
+
tracker=Hash.new
|
39
|
+
tracker['host']=host
|
40
|
+
tracker['ip']=ip
|
41
|
+
tracker['cidr']=cidr
|
42
|
+
tracker['ref']=ref
|
43
|
+
tracker['netname']=netname
|
44
|
+
return tracker
|
45
|
+
rescue => ee
|
46
|
+
puts "Exception on method #{__method__} for host #{host}: #{ee}" # if @verbose
|
47
|
+
return nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
alias_method :track, :cidr_worker
|
51
|
+
|
52
|
+
# 'setter' to load the known CIDR blocks into an instance variable @known_cidr_blks
|
53
|
+
def load_cidr_blks_from_file (file_cidrs=@file_cidr_seeds)
|
54
|
+
puts "Load the known CIDR seed file: #{file_cidrs}" if @verbose
|
55
|
+
begin
|
56
|
+
f=File.open(file_cidrs, 'r')
|
57
|
+
f.each do |line|
|
58
|
+
entry=line.chomp.split(',')
|
59
|
+
next unless is_cidr?(entry[0])
|
60
|
+
puts "Loading: #{entry[0]}" if @verbose
|
61
|
+
key=entry[0].strip
|
62
|
+
@known_cidr_blks[key] = Hash.new if not @known_cidr_blks.key?(key)
|
63
|
+
@known_cidr_blks[key]['ref']=entry[1].nil? ? nil : entry[1].strip
|
64
|
+
@known_cidr_blks[key]['netname']=entry[2].nil? ? nil : entry[2].strip
|
65
|
+
end
|
66
|
+
f.close
|
67
|
+
# Sort the blocks in order once for better performance
|
68
|
+
@known_cidr_blks_desc_index=NetAddr.sort(@known_cidr_blks.keys, :Desc=>true)
|
69
|
+
@known_cidr_blks_asce_index=NetAddr.sort(@known_cidr_blks.keys, :Desc=>false)
|
70
|
+
rescue => ee
|
71
|
+
puts "Exception on method #{__method__}: #{ee}" # if @verbose
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# 'setter' to add an entry to CIDR store @known_cidr_blks
|
76
|
+
def add (cidr,ref=nil,netname=nil)
|
77
|
+
puts "Load the entry into the CIDR store: #{cidr}"
|
78
|
+
begin
|
79
|
+
raise "Unknown CIDR format: #{cidr}" unless is_cidr?(cidr)
|
80
|
+
# Obtain the 'ref' and 'netname' value automatically in case not passed as method parameters
|
81
|
+
if ref.nil? or netname.nil?
|
82
|
+
whois = Wmap::Whois.new
|
83
|
+
# Note 11/1/2014: Use IP instead of the CIDR to perform the query, as the current ruby-whois query does not support CIDR as query input
|
84
|
+
ip=cidr.split("/")[0]
|
85
|
+
ref=whois.get_net_desc(ip)
|
86
|
+
netname=whois.get_netname(ip)
|
87
|
+
whois=nil
|
88
|
+
end
|
89
|
+
if @known_cidr_blks.key?(cidr)
|
90
|
+
puts "Skip! Entry is already exist: #{cidr}"
|
91
|
+
return nil
|
92
|
+
else
|
93
|
+
@known_cidr_blks[cidr] = Hash.new
|
94
|
+
@known_cidr_blks[cidr]['ref']=ref
|
95
|
+
@known_cidr_blks[cidr]['netname']=netname
|
96
|
+
puts "Entry loaded!"
|
97
|
+
end
|
98
|
+
# Re-sort the blocks in order for better performance
|
99
|
+
@known_cidr_blks_desc_index=NetAddr.sort(@known_cidr_blks.keys, :Desc=>true)
|
100
|
+
@known_cidr_blks_asce_index=NetAddr.sort(@known_cidr_blks.keys, :Desc=>false)
|
101
|
+
rescue => ee
|
102
|
+
puts "Exception on method #{__method__}: #{ee}" # if @verbose
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# 'setter' to remove an entry to CIDR store @known_cidr_blks
|
107
|
+
def delete (cidr,ref=nil,netname=nil)
|
108
|
+
puts "Remove the entry from the CIDR store: #{cidr}"
|
109
|
+
begin
|
110
|
+
#cidr.strip!
|
111
|
+
raise "Unknown CIDR format: #{cidr}" unless is_cidr?(cidr)
|
112
|
+
if @known_cidr_blks.key?(cidr)
|
113
|
+
puts "Deleting ..."
|
114
|
+
@known_cidr_blks.delete(cidr)
|
115
|
+
puts "Entry cleared!"
|
116
|
+
else
|
117
|
+
raise "Unknown CIDR entry: #{cidr}"
|
118
|
+
end
|
119
|
+
# Re-sort the blocks in order for better performance
|
120
|
+
@known_cidr_blks_desc_index=NetAddr.sort(@known_cidr_blks.keys, :Desc=>true)
|
121
|
+
@known_cidr_blks_asce_index=NetAddr.sort(@known_cidr_blks.keys, :Desc=>false)
|
122
|
+
rescue => ee
|
123
|
+
puts "Exception on method #{__method__}: #{ee}" # if @verbose
|
124
|
+
end
|
125
|
+
end
|
126
|
+
alias_method :del, :delete
|
127
|
+
|
128
|
+
# Count numbers of CIDR object entries in the CIDR cache table
|
129
|
+
def count
|
130
|
+
puts "Counting number of entries in the CIDR cache table ..." if @verbose
|
131
|
+
begin
|
132
|
+
cnt=0
|
133
|
+
@known_cidr_blks.keys.map do |key|
|
134
|
+
if is_cidr?(key)
|
135
|
+
cnt=cnt+1
|
136
|
+
end
|
137
|
+
end
|
138
|
+
puts "Current number of CIDR object entries: #{cnt}" if @verbose
|
139
|
+
return cnt
|
140
|
+
rescue => ee
|
141
|
+
puts "Exception on method #{__method__}: #{ee}" if @verbose
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Count numbers of IPs within the trusted CIDR objects
|
146
|
+
def counts
|
147
|
+
puts "Counting number of IPs within the CIDR store:" if @verbose
|
148
|
+
begin
|
149
|
+
cnt=0
|
150
|
+
@known_cidr_blks.keys.map do |key|
|
151
|
+
cnt=cnt+size(key)
|
152
|
+
end
|
153
|
+
puts "Total number of trusted IPs: #{cnt}" if @verbose
|
154
|
+
return cnt
|
155
|
+
rescue => ee
|
156
|
+
puts "Exception on method #{__method__}: #{ee}" if @verbose
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# Check if the specific IP within the range of a list of known CIDR blocks
|
161
|
+
def ip_trusted? (ip)
|
162
|
+
puts "Check if the IP within the range of the known CIDR blocks: #{ip}" if @verbose
|
163
|
+
known = false
|
164
|
+
begin
|
165
|
+
return false if @known_cidr_blks==nil
|
166
|
+
first_octet_ip = ip.split('.').first.to_i
|
167
|
+
@known_cidr_blks_desc_index.each do |line|
|
168
|
+
first_octet_blk = line.split('.').first.to_i
|
169
|
+
next if first_octet_blk > first_octet_ip
|
170
|
+
cidr4 = NetAddr::CIDR.create(line)
|
171
|
+
known = cidr4.contains?(ip+'/32')
|
172
|
+
break if known
|
173
|
+
end
|
174
|
+
rescue => ee
|
175
|
+
if @verbose
|
176
|
+
puts "Exception on method #{__method__}: #{ee}"
|
177
|
+
end
|
178
|
+
return false
|
179
|
+
end
|
180
|
+
return known
|
181
|
+
end
|
182
|
+
alias_method :is_trusted?, :ip_trusted?
|
183
|
+
|
184
|
+
# Return the matching CIDR block for a ip
|
185
|
+
def cidr_lookup (ip)
|
186
|
+
puts "Lookup the CIDR name from the known CIDR list for the IP: #{ip}" if @verbose
|
187
|
+
begin
|
188
|
+
return nil if @known_cidr_blks==nil
|
189
|
+
puts "CIDR Lookup: #{ip} ..." if @verbose
|
190
|
+
@known_cidr_blks_desc_index.each do |line|
|
191
|
+
first_octet_ip = ip.split('.').first.to_i
|
192
|
+
first_octet_blk = line.split('.').first.to_i
|
193
|
+
next if first_octet_blk > first_octet_ip
|
194
|
+
cidr4 = NetAddr::CIDR.create(line)
|
195
|
+
known = cidr4.contains?(ip+'/32')
|
196
|
+
return line if known
|
197
|
+
end
|
198
|
+
rescue => ee
|
199
|
+
puts "Exception on method #{__method__}: #{ee}" if @verbose
|
200
|
+
return nil
|
201
|
+
end
|
202
|
+
return nil
|
203
|
+
end
|
204
|
+
alias_method :lookup, :cidr_lookup
|
205
|
+
alias_method :query, :cidr_lookup
|
206
|
+
|
207
|
+
# Determine if a CIDR entry is already known
|
208
|
+
def cidr_known? (cidr)
|
209
|
+
puts "Determine if the CIDR is known: #{cidr}" if @verbose
|
210
|
+
known=false
|
211
|
+
cidr=cidr.strip unless cidr.nil?
|
212
|
+
cidr=cidr+"/32" if is_ip?(cidr)
|
213
|
+
begin
|
214
|
+
raise "Invalid CIDR format: #{cidr}" unless is_cidr?(cidr)
|
215
|
+
return false if @known_cidr_blks==nil
|
216
|
+
return true if @known_cidr_blks.key?(cidr)
|
217
|
+
rescue => ee
|
218
|
+
puts "Exception on method #{__method__}: #{ee}" if @verbose
|
219
|
+
return false
|
220
|
+
end
|
221
|
+
return known
|
222
|
+
end
|
223
|
+
alias_method :is_known?, :cidr_known?
|
224
|
+
|
225
|
+
# Determine if a cidr is within the range of our known network CIDR blocks
|
226
|
+
def cidr_trusted? (cidr)
|
227
|
+
puts "Determine if the CIDR within our ranges: #{cidr}" if @verbose
|
228
|
+
trusted=false
|
229
|
+
cidr=cidr.strip unless cidr.nil?
|
230
|
+
cidr=cidr+"/32" if is_ip?(cidr)
|
231
|
+
begin
|
232
|
+
raise "Invalid CIDR format: #{cidr}" unless is_cidr?(cidr)
|
233
|
+
return false if @known_cidr_blks==nil
|
234
|
+
return true if @known_cidr_blks.key?(cidr)
|
235
|
+
@known_cidr_blks_asce_index.each do |line|
|
236
|
+
cidr4 = NetAddr::CIDR.create(line)
|
237
|
+
return true if cidr4.contains?(cidr)
|
238
|
+
end
|
239
|
+
rescue => ee
|
240
|
+
puts "Exception on method #{__method__}: #{ee}" if @verbose
|
241
|
+
return false
|
242
|
+
end
|
243
|
+
return trusted
|
244
|
+
end
|
245
|
+
alias_method :is_trusted?, :cidr_trusted?
|
246
|
+
|
247
|
+
# NetAddr wrapper to determine number of IPs within the CIDR object.
|
248
|
+
def size (cidr)
|
249
|
+
puts "Determine the size of CIDR object: #{cidr}" if @verbose
|
250
|
+
begin
|
251
|
+
raise "Invalid CIDR format: #{cidr}" unless is_cidr?(cidr)
|
252
|
+
obj = NetAddr::CIDR.create(cidr)
|
253
|
+
return obj.size.to_i
|
254
|
+
rescue => ee
|
255
|
+
puts "Exception on method #{__method__}: #{ee}" if @verbose
|
256
|
+
return nil
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
# Retrieve the CIDR reference text for tracking purpose, if it's a known CIDR entry
|
261
|
+
def get_cidr_ref (cidr)
|
262
|
+
puts "Lookup CIDR block #{cidr} reference text ..." if @verbose
|
263
|
+
cidr=cidr.strip unless cidr.nil?
|
264
|
+
return nil unless @known_cidr_blks.key?(cidr)
|
265
|
+
return @known_cidr_blks[cidr]['ref']
|
266
|
+
end
|
267
|
+
|
268
|
+
# Retrieve the CIDR netname field for tracking purpose, if it's a known CIDR entry
|
269
|
+
def get_cidr_netname (cidr)
|
270
|
+
puts "Lookup CIDR block #{cidr} netname ..." if @verbose
|
271
|
+
cidr=cidr.strip unless cidr.nil?
|
272
|
+
return nil unless @known_cidr_blks.key?(cidr)
|
273
|
+
return @known_cidr_blks[cidr]['netname']
|
274
|
+
end
|
275
|
+
|
276
|
+
# Save the current cidr hash table into a file
|
277
|
+
def save_cidrs_to_file!(file_cidrs=@file_cidr_seeds)
|
278
|
+
puts "Saving the current cidrs cache table from memory to file: #{file_cidrs} ..." if @verbose
|
279
|
+
begin
|
280
|
+
timestamp=Time.now
|
281
|
+
f=File.open(file_cidrs, 'w')
|
282
|
+
f.write "# Local cidrs file created by Wmap::CidrTracker.save method at: #{timestamp}\n"
|
283
|
+
f.write "Network CIDR, CIDR RIPE Reference Text, CIDR NETNAME\n"
|
284
|
+
@known_cidr_blks_asce_index.map do |key|
|
285
|
+
ref=get_cidr_ref(key)
|
286
|
+
netname=get_cidr_netname(key)
|
287
|
+
f.write "#{key},#{ref},#{netname}\n"
|
288
|
+
end
|
289
|
+
f.close
|
290
|
+
puts "CIDR cache table is successfully saved: #{file_cidrs}"
|
291
|
+
rescue => ee
|
292
|
+
puts "Exception on method #{__method__}: #{ee}" if @verbose
|
293
|
+
end
|
294
|
+
end
|
295
|
+
alias_method :save!, :save_cidrs_to_file!
|
296
|
+
|
297
|
+
# Print summary report of a list of known CIDR blocks
|
298
|
+
def print_known_cidr_blks
|
299
|
+
puts "Print the known CIDR Netblocks in ascendant order" if @verbose
|
300
|
+
puts "Network CIDR, RIPE Reference Text, NETNAME"
|
301
|
+
@known_cidr_blks_asce_index.map do |key|
|
302
|
+
ref=@known_cidr_blks[key]['ref']
|
303
|
+
netname=@known_cidr_blks[key]['netname']
|
304
|
+
puts "#{key}, #{ref}, #{netname}"
|
305
|
+
end
|
306
|
+
puts "End of the summary"
|
307
|
+
end
|
308
|
+
alias_method :inspect, :print_known_cidr_blks
|
309
|
+
|
310
|
+
# Print summary report of a list of known CIDR blocks in the descendant order
|
311
|
+
def print_known_cidr_blks_desc
|
312
|
+
puts "\nIndex of known CIDR Net blocks in Descendant Order:"
|
313
|
+
puts @known_cidr_blks_desc_index
|
314
|
+
puts "End of the Index"
|
315
|
+
end
|
316
|
+
|
317
|
+
# Print summary report of a list of known CIDR blocks in the ascendant order
|
318
|
+
def print_known_cidr_blks_asce
|
319
|
+
puts "\nIndex of known CIDR Net blocks in Ascending Order:"
|
320
|
+
puts @known_cidr_blks_asce_index
|
321
|
+
puts "End of the Index"
|
322
|
+
end
|
323
|
+
alias_method :print, :print_known_cidr_blks_asce
|
324
|
+
|
325
|
+
private :load_cidr_blks_from_file
|
326
|
+
|
327
|
+
end
|