antfarm-core 0.5.0.beta1
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/README.md +190 -0
- data/config/boot.rb +40 -0
- data/config/environment.rb +30 -0
- data/lib/antfarm-core.rb +167 -0
- data/lib/antfarm/errors.rb +42 -0
- data/lib/antfarm/framework.rb +166 -0
- data/lib/antfarm/helpers.rb +146 -0
- data/lib/antfarm/initializer.rb +160 -0
- data/lib/antfarm/models.rb +51 -0
- data/lib/antfarm/models/ethernet_interface.rb +84 -0
- data/lib/antfarm/models/ip_interface.rb +134 -0
- data/lib/antfarm/models/ip_network.rb +118 -0
- data/lib/antfarm/models/layer_three_interface.rb +88 -0
- data/lib/antfarm/models/layer_three_network.rb +151 -0
- data/lib/antfarm/models/layer_two_interface.rb +96 -0
- data/lib/antfarm/models/node.rb +61 -0
- data/lib/antfarm/plugin.rb +177 -0
- data/lib/antfarm/plugins/cisco/parse-arp.rb +90 -0
- data/lib/antfarm/plugins/cisco/parse-interfaces.rb +126 -0
- data/lib/antfarm/plugins/cisco/parse-network-objects.rb +105 -0
- data/lib/antfarm/plugins/cisco/parse-pix-config.rb +243 -0
- data/lib/antfarm/plugins/load-host.rb +105 -0
- data/lib/antfarm/plugins/load-network.rb +71 -0
- data/lib/antfarm/plugins/nmap/parse-xml.rb +84 -0
- data/lib/antfarm/version.rb +9 -0
- data/lib/tasks/spec.rake +56 -0
- data/man/antfarm-plugins.1 +69 -0
- data/man/antfarm-plugins.1.ronn +57 -0
- metadata +186 -0
data/README.md
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
# ANTFARM-CORE
|
2
|
+
|
3
|
+
ANTFARM (Advanced Network Toolkit For Assessments and Remote Mapping) is a
|
4
|
+
passive network mapping application that utilizes output from existing network
|
5
|
+
examination tools to populate its OSI-modeled database. This data can then be
|
6
|
+
used to form a ‘picture’ of the network being analyzed.
|
7
|
+
|
8
|
+
ANTFARM can also be described as a data fusion tool that does not directly
|
9
|
+
interact with the network. The analyst can use a variety of passive or active
|
10
|
+
data gathering techniques, the outputs of which are loaded into ANTFARM and
|
11
|
+
incorporated into the network map. Data gathering can be limited to completely
|
12
|
+
passive techniques when minimizing the risk of disrupting the operational
|
13
|
+
network is a concern.
|
14
|
+
|
15
|
+
This library implements the core ANTFARM functionality, which mainly facilitates
|
16
|
+
creating and interacting with the relational database that holds and correlates
|
17
|
+
network data as it is parsed. This library is not meant to stand alone, but
|
18
|
+
rather be part of a larger application needing ANTFARM functionality. Please
|
19
|
+
see the ANTFARM (as opposed to the ANTFARM-CORE) library if you are looking for
|
20
|
+
the command-line application.
|
21
|
+
|
22
|
+
## STATUS OF BETA RELEASE
|
23
|
+
|
24
|
+
Please note that not all of the database models and plugins available in
|
25
|
+
version 0.4.0 are available in the beta release of version 0.5.0. The 'beta'
|
26
|
+
status will be removed once all the functionality available in version 0.4.0 is
|
27
|
+
implemented in version 0.5.0.
|
28
|
+
|
29
|
+
The database models not yet available in the beta release of version 0.5.0 are:
|
30
|
+
|
31
|
+
* Action
|
32
|
+
* DnsEntry
|
33
|
+
* OperatingSystem
|
34
|
+
* PrivateNetwork
|
35
|
+
* Service
|
36
|
+
* Traffic
|
37
|
+
|
38
|
+
Note that in order to install a pre-release version of a gem (such as the beta
|
39
|
+
version of ANTFARM 0.5.0), you must specify the --pre-release option when using
|
40
|
+
'gem install' along with the full version name (i.e. --version 0.5.0.beta).
|
41
|
+
|
42
|
+
## HOW IT WORKS
|
43
|
+
|
44
|
+
At the center of the ANTFARM-CORE library is a boot-strapping and initialization
|
45
|
+
process very similar to the one used in Rails applications. The boot-strapping
|
46
|
+
and initialization process sets the root directory, the environment to use (used
|
47
|
+
by the database and logging features), the log level to use, and loads in all
|
48
|
+
the database models (see below).
|
49
|
+
|
50
|
+
DataMapper is used as the ORM for interacting with the database, and models
|
51
|
+
exist for the following database tables:
|
52
|
+
|
53
|
+
* Node
|
54
|
+
* LayerTwoInterface
|
55
|
+
* EthernetInterface
|
56
|
+
* LayerThreeInterface
|
57
|
+
* IpInterface
|
58
|
+
* LayerThreeNetwork
|
59
|
+
* IpNetwork
|
60
|
+
|
61
|
+
These models live in the Antfarm::Model namespace.
|
62
|
+
|
63
|
+
A framework is provided to facilitate interaction with plugins and manipulation
|
64
|
+
of the database.
|
65
|
+
|
66
|
+
## THINGS TO KNOW
|
67
|
+
|
68
|
+
The ANTFARM environment and log settings can (and should) be set via the
|
69
|
+
described environment variables below as long as they are set before the
|
70
|
+
config/environment.rb file is loaded.
|
71
|
+
|
72
|
+
ENV['ANTFARM_ENV'] = 'foo'
|
73
|
+
ENV['ANTFARM_LOG_LEVEL'] = 'debug'
|
74
|
+
|
75
|
+
When ANTFARM is boot-strapped, it will check to see if a .antfarm directory
|
76
|
+
exists in the home directory of the current user and will create it if not.
|
77
|
+
This is where application-specific data is stored, like default environment
|
78
|
+
and log level settings, database settings, SQLite3 databases (if used), and
|
79
|
+
log files. Custom user plugins can also be placed in the .antfarm directory
|
80
|
+
and they will be recognized by the plugins library.
|
81
|
+
|
82
|
+
## DATABASE SETTINGS
|
83
|
+
|
84
|
+
Right now, only SQLite3 is supported. As such, it is the default. Future plans
|
85
|
+
include supporting Postgres as well, in which case different databases can be
|
86
|
+
configured for different environments via the default settings in the .antfarm
|
87
|
+
directory.
|
88
|
+
|
89
|
+
## PLUGINS
|
90
|
+
|
91
|
+
Detailed information for each plugin is provided via the ANTFARM-PLUGINS man
|
92
|
+
page (`gem man antfarm-plugins`). Plugins included in the core library are
|
93
|
+
located in the 'lib/antfarm/plugins/' directory, and custom plugins created by
|
94
|
+
a user would/should be located in the '~/.antfarm/plugins' directory.
|
95
|
+
|
96
|
+
## HOW TO WRITE A PLUGIN
|
97
|
+
|
98
|
+
The requirements for a plugin are as follows:
|
99
|
+
|
100
|
+
* Plugin must belong to the Antfarm::Plugin namespace
|
101
|
+
* Below the Antfarm::Plugin namespace, namespacing must follow the directory
|
102
|
+
structure of the location of the plugin
|
103
|
+
* Plugin must include the Antfarm::Plugin module
|
104
|
+
* Plugin must provide a hash that describes the plugin and an array of hashes
|
105
|
+
that describe possible plugin options to 'super' in the constructor
|
106
|
+
** Required description options are :name, :desc, and :author
|
107
|
+
** Required parameter options are :name, :desc, :type, :default and :required
|
108
|
+
* Plugin must implement a 'run' method that accepts a single hash parameter
|
109
|
+
** The single hash parameter will contain options provided as described in the
|
110
|
+
constructor
|
111
|
+
|
112
|
+
Here is a very simple example plugin located at 'plugins/custom/foo-bar.rb':
|
113
|
+
|
114
|
+
module Antfarm
|
115
|
+
module Plugin
|
116
|
+
module Custom
|
117
|
+
class FooBar
|
118
|
+
include Antfarm::Plugin
|
119
|
+
|
120
|
+
def initialize
|
121
|
+
super( { :name => 'Foo Bar Plugin',
|
122
|
+
:desc => 'This plugin does nothing',
|
123
|
+
:author => 'Me <me@you.com>' },
|
124
|
+
[{ :name => :input_file,
|
125
|
+
:desc => 'File that has data in it',
|
126
|
+
:type => String,
|
127
|
+
:required => true },
|
128
|
+
{ :name => :use,
|
129
|
+
:desc => 'To use or not to use' }
|
130
|
+
])
|
131
|
+
end
|
132
|
+
|
133
|
+
def run(options)
|
134
|
+
# options[:input_file] will contain a string
|
135
|
+
# options[:use] will either be true or false, depending on whether or
|
136
|
+
# not the user provided the flag
|
137
|
+
|
138
|
+
# TODO: do something!
|
139
|
+
# Database models can be used like so:
|
140
|
+
# Antfarm::Model::IpInterface.create :address => 'w.x.y.z'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
Note that for optional parameters, if a type is not provided it is assumed to be
|
148
|
+
a flag (true if the flag is provided, false if not). Obviously the default will
|
149
|
+
be false and it is not required.
|
150
|
+
|
151
|
+
## VERSIONING INFORMATION
|
152
|
+
|
153
|
+
This project uses the major/minor/bugfix method of versioning. It has yet to
|
154
|
+
reach a 1.x.x status yet because the API is still in flux. When new plugins are
|
155
|
+
officially released, the minor version number will be incremented.
|
156
|
+
|
157
|
+
## DISCLAIMER
|
158
|
+
|
159
|
+
While the ANTFARM-CORE library is completely passive (it does not have any
|
160
|
+
built-in means of gathering data directly from devices or networks), network
|
161
|
+
admin tools that users of ANTFARM may choose to gather data with may or may not
|
162
|
+
be passive. The authors of ANTFARM hold no responsibility in how users decide to
|
163
|
+
gather data they wish to feed into ANTFARM.
|
164
|
+
|
165
|
+
## COPYRIGHT
|
166
|
+
|
167
|
+
Copyright (2008-2010) Sandia Corporation. Under the terms of Contract
|
168
|
+
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain
|
169
|
+
rights in this software.
|
170
|
+
|
171
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
172
|
+
this software and associated documentation files (the "Software"), to deal in
|
173
|
+
the Software without restriction, including without limitation the rights to
|
174
|
+
use, copy, modify, merge, publish, distribute, distribute with modifications,
|
175
|
+
sublicense, and/or sell copies of the Software, and to permit persons to whom
|
176
|
+
the Software is furnished to do so, subject to the following conditions:
|
177
|
+
|
178
|
+
The above copyright notice and this permission notice shall be included in all
|
179
|
+
copies or substantial portions of the Software.
|
180
|
+
|
181
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
182
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
183
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
184
|
+
ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
185
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
186
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
187
|
+
|
188
|
+
Except as contained in this notice, the name(s) of the above copyright holders
|
189
|
+
shall not be used in advertising or otherwise to promote the sale, use or other
|
190
|
+
dealings in this Software without prior written authorization.
|
data/config/boot.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (2008) Sandia Corporation.
|
2
|
+
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
3
|
+
# the U.S. Government retains certain rights in this software.
|
4
|
+
#
|
5
|
+
# Original Author: Bryan T. Richardson, Sandia National Laboratories <btricha@sandia.gov>
|
6
|
+
#
|
7
|
+
# This library is free software; you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation; either version 2.1 of the License, or (at
|
10
|
+
# your option) any later version.
|
11
|
+
#
|
12
|
+
# This library is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
14
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
15
|
+
# details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this library; if not, write to the Free Software Foundation, Inc.,
|
19
|
+
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
#
|
21
|
+
# This script is modeled after the Rails boot script.
|
22
|
+
|
23
|
+
ANTFARM_ROOT = (ENV['ANTFARM_ROOT'] || File.expand_path(File.dirname(__FILE__) + '/..')).dup unless defined? ANTFARM_ROOT
|
24
|
+
|
25
|
+
module Antfarm
|
26
|
+
class << self
|
27
|
+
def boot!
|
28
|
+
unless booted?
|
29
|
+
require ANTFARM_ROOT + '/lib/antfarm/initializer'
|
30
|
+
Antfarm::Initializer.run(:setup)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def booted?
|
35
|
+
defined? Antfarm::Initializer
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Antfarm.boot!
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Copyright (2008) Sandia Corporation.
|
2
|
+
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
3
|
+
# the U.S. Government retains certain rights in this software.
|
4
|
+
#
|
5
|
+
# Original Author: Bryan T. Richardson, Sandia National Laboratories <btricha@sandia.gov>
|
6
|
+
#
|
7
|
+
# This library is free software; you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation; either version 2.1 of the License, or (at
|
10
|
+
# your option) any later version.
|
11
|
+
#
|
12
|
+
# This library is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
14
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
15
|
+
# details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this library; if not, write to the Free Software Foundation, Inc.,
|
19
|
+
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
#
|
21
|
+
# This script is modeled after the Rails environment configuration script.
|
22
|
+
|
23
|
+
ANTFARM_ENV = (ENV['ANTFARM_ENV'] || 'antfarm').dup unless defined? ANTFARM_ENV
|
24
|
+
ANTFARM_LOG_LEVEL = (ENV['ANTFARM_LOG_LEVEL'] || 'warn').dup unless defined? ANTFARM_LOG_LEVEL
|
25
|
+
|
26
|
+
require File.dirname(__FILE__) + '/boot'
|
27
|
+
|
28
|
+
Antfarm::Initializer.run do |config|
|
29
|
+
config.log_level = ANTFARM_LOG_LEVEL
|
30
|
+
end
|
data/lib/antfarm-core.rb
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
################################################################################
|
2
|
+
# #
|
3
|
+
# Copyright (2008-2010) Sandia Corporation. Under the terms of Contract #
|
4
|
+
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains #
|
5
|
+
# certain rights in this software. #
|
6
|
+
# #
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy #
|
8
|
+
# of this software and associated documentation files (the "Software"), to #
|
9
|
+
# deal in the Software without restriction, including without limitation the #
|
10
|
+
# rights to use, copy, modify, merge, publish, distribute, distribute with #
|
11
|
+
# modifications, sublicense, and/or sell copies of the Software, and to permit #
|
12
|
+
# persons to whom the Software is furnished to do so, subject to the following #
|
13
|
+
# conditions: #
|
14
|
+
# #
|
15
|
+
# The above copyright notice and this permission notice shall be included in #
|
16
|
+
# all copies or substantial portions of the Software. #
|
17
|
+
# #
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
|
21
|
+
# ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, #
|
22
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR #
|
23
|
+
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
|
24
|
+
# SOFTWARE. #
|
25
|
+
# #
|
26
|
+
# Except as contained in this notice, the name(s) of the above copyright #
|
27
|
+
# holders shall not be used in advertising or otherwise to promote the sale, #
|
28
|
+
# use or other dealings in this Software without prior written authorization. #
|
29
|
+
# #
|
30
|
+
################################################################################
|
31
|
+
|
32
|
+
require 'ipaddr'
|
33
|
+
|
34
|
+
require File.dirname(__FILE__) + '/../config/boot'
|
35
|
+
|
36
|
+
require 'antfarm/helpers'
|
37
|
+
require 'antfarm/models'
|
38
|
+
require 'antfarm/version'
|
39
|
+
|
40
|
+
module Antfarm
|
41
|
+
# Some explanation to having @netmask and such:
|
42
|
+
# If you create a new IPAddr object and you include
|
43
|
+
# the network information for the IP address, IPAddr
|
44
|
+
# doesn't keep track of the actual address, and
|
45
|
+
# instead just keeps track of the network. For
|
46
|
+
# example, if you were to create a new IPAddr object
|
47
|
+
# using the following code:
|
48
|
+
#
|
49
|
+
# IPAddr.new("192.168.101.5/24")
|
50
|
+
#
|
51
|
+
# the resulting object would be of the form:
|
52
|
+
#
|
53
|
+
# <IPAddr: IPv4:192.168.101.0/255.255.255.0>
|
54
|
+
#
|
55
|
+
# and there would be no way to retrieve the original
|
56
|
+
# address (192.168.101.5). By creating this class,
|
57
|
+
# Michael has made it possible to keep track of both
|
58
|
+
# the address and the network information. This is
|
59
|
+
# useful in the case of creating a new IPInterface
|
60
|
+
# object.
|
61
|
+
#
|
62
|
+
# TODO: If a netmask is given, should we somehow check
|
63
|
+
# to see if an address is being given with network
|
64
|
+
# information or if a network is being specified,
|
65
|
+
# and if it is a network, should we validate that
|
66
|
+
# the network address is valid with the given
|
67
|
+
# netmask? This may be done automatically... I
|
68
|
+
# need to look more into how IPAddr works.
|
69
|
+
|
70
|
+
class IPAddrExt < IPAddr
|
71
|
+
def initialize(value)
|
72
|
+
address,netmask = value.split('/')
|
73
|
+
super(address)
|
74
|
+
|
75
|
+
if self.ipv4?
|
76
|
+
@netmask = IPAddr.new('255.255.255.255')
|
77
|
+
@addr_bits = 32
|
78
|
+
elsif self.ipv6?
|
79
|
+
@netmask = IPAddr.new('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff')
|
80
|
+
@addr_bits = 128
|
81
|
+
else
|
82
|
+
#TODO: Error
|
83
|
+
end
|
84
|
+
|
85
|
+
if netmask
|
86
|
+
@netmask = @netmask.mask(netmask)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
attr_accessor :netmask
|
91
|
+
|
92
|
+
def netmask_length
|
93
|
+
mask_len = @addr_bits
|
94
|
+
unless (~@netmask).to_i == 0
|
95
|
+
res = Math.log((~@netmask).to_i) / Math.log(2)
|
96
|
+
if res.finite?
|
97
|
+
mask_len -= res.round
|
98
|
+
end
|
99
|
+
end
|
100
|
+
return mask_len
|
101
|
+
end
|
102
|
+
|
103
|
+
def network
|
104
|
+
return self.mask(self.netmask.to_s)
|
105
|
+
end
|
106
|
+
|
107
|
+
def to_cidr_string
|
108
|
+
return sprintf("%s/%s", self.network.to_string, self.netmask_length.to_s)
|
109
|
+
end
|
110
|
+
|
111
|
+
def broadcast
|
112
|
+
return self.network | ~self.netmask
|
113
|
+
end
|
114
|
+
|
115
|
+
# TODO: track down the IPv6 private use ranges and include them
|
116
|
+
def private_address?
|
117
|
+
private_addr_list = [ '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16',
|
118
|
+
'fe80::/10', 'fec0::/10' ]
|
119
|
+
return self.in_address_list?(private_addr_list)
|
120
|
+
end
|
121
|
+
|
122
|
+
#TODO: track down IPv6 localnet mask (guessing /10 for now)
|
123
|
+
def loopback_address?
|
124
|
+
loopback_addr_list = ['127.0.0.0/8', '::1', 'fe00::/10']
|
125
|
+
return self.in_address_list?(loopback_addr_list)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Need to verify the IPv4 multicast addrs (couldn't find the whole
|
129
|
+
# block, only the currently assigned ranges within the block)
|
130
|
+
def multicast_address?
|
131
|
+
multicast_addr_list = ['224.0.0.0/4', 'ff00::/8']
|
132
|
+
return self.in_address_list?(multicast_addr_list)
|
133
|
+
end
|
134
|
+
|
135
|
+
def in_address_list?(addr_str_list)
|
136
|
+
for addr_str in addr_str_list
|
137
|
+
addr = IPAddr.new(addr_str)
|
138
|
+
if addr.include?(self)
|
139
|
+
return true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
return false
|
143
|
+
end
|
144
|
+
|
145
|
+
# Decides if the given network is a subset of this network.
|
146
|
+
# This method was added since SQLite3 cannot handle CIDR's
|
147
|
+
# 'natively' like PostgreSQL can. Note that this method
|
148
|
+
# also works if the network given is actually a host.
|
149
|
+
def network_in_network?(network)
|
150
|
+
broadcast = nil
|
151
|
+
|
152
|
+
if network.kind_of?(String)
|
153
|
+
broadcast = IPAddrExt.new(network).broadcast
|
154
|
+
network = IPAddr.new(network)
|
155
|
+
elsif network.kind_of?(Antfarm::IPAddrExt)
|
156
|
+
broadcast = network.broadcast
|
157
|
+
network = IPAddr.new(network.to_cidr_string)
|
158
|
+
else
|
159
|
+
raise(ArgumentError, "argument should be either a String or an Antfarm::IPAddrExt object", caller)
|
160
|
+
end
|
161
|
+
|
162
|
+
return false unless IPAddr.new(self.to_cidr_string).include?(network)
|
163
|
+
return false unless IPAddr.new(self.to_cidr_string).include?(broadcast)
|
164
|
+
return true
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
################################################################################
|
2
|
+
# #
|
3
|
+
# Copyright (2008-2010) Sandia Corporation. Under the terms of Contract #
|
4
|
+
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains #
|
5
|
+
# certain rights in this software. #
|
6
|
+
# #
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy #
|
8
|
+
# of this software and associated documentation files (the "Software"), to #
|
9
|
+
# deal in the Software without restriction, including without limitation the #
|
10
|
+
# rights to use, copy, modify, merge, publish, distribute, distribute with #
|
11
|
+
# modifications, sublicense, and/or sell copies of the Software, and to permit #
|
12
|
+
# persons to whom the Software is furnished to do so, subject to the following #
|
13
|
+
# conditions: #
|
14
|
+
# #
|
15
|
+
# The above copyright notice and this permission notice shall be included in #
|
16
|
+
# all copies or substantial portions of the Software. #
|
17
|
+
# #
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
|
21
|
+
# ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, #
|
22
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR #
|
23
|
+
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
|
24
|
+
# SOFTWARE. #
|
25
|
+
# #
|
26
|
+
# Except as contained in this notice, the name(s) of the above copyright #
|
27
|
+
# holders shall not be used in advertising or otherwise to promote the sale, #
|
28
|
+
# use or other dealings in this Software without prior written authorization. #
|
29
|
+
# #
|
30
|
+
################################################################################
|
31
|
+
|
32
|
+
module Antfarm
|
33
|
+
class AntfarmError < RuntimeError
|
34
|
+
def initialize(message)
|
35
|
+
super
|
36
|
+
|
37
|
+
message = "#{self.class}: #{message}"
|
38
|
+
Antfarm::Helpers.output("Exception: #{message}")
|
39
|
+
Antfarm::Helpers.log :error, message
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|