Class: Ronin::DB::Port
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ronin::DB::Port
- Includes:
- Model
- Defined in:
- lib/ronin/db/port.rb
Overview
Represents a TCP or UDP port.
Instance Attribute Summary collapse
-
#created_at ⇒ Time
readonly
Defines the created_at timestamp.
-
#id ⇒ Integer
The primary key of the port.
-
#ip_addresses ⇒ Array<IPAddress>
The IP Addresses that that have this port open.
-
#notes ⇒ Array<Note>
The associated notes.
-
#number ⇒ Integer
The port number.
-
#open_ports ⇒ Array<OpenPort>
The open ports.
-
#protocol ⇒ "tcp", "udp"
The protocol of the port (either
'tcp'
/'udp'
). -
#services ⇒ Array<Service>
The services that that use this port.
Class Method Summary collapse
-
.import(number) ⇒ Port
Creates a new Port.
-
.lookup(number) ⇒ Port?
Looks up a port by it's number.
-
.with_ip_address(address) ⇒ Array<Port>
Queries all ports associated with the IP address.
-
.with_number(number) ⇒ Array<Port>
Queries all ports with the port number or in the port range.
-
.with_protocol(protocol) ⇒ Array<Port>
Queries all ports with the protocol.
-
.with_service_name(name) ⇒ Array<Port>
Queries all ports associated with the service name.
Instance Method Summary collapse
-
#to_i ⇒ Integer
Converts the port to an integer.
-
#to_s ⇒ String
Converts the port to a string.
Methods included from Model
Instance Attribute Details
#created_at ⇒ Time (readonly)
Defines the created_at timestamp
65 |
# File 'lib/ronin/db/port.rb', line 65 attribute :created_at, :datetime |
#id ⇒ Integer
The primary key of the port.
38 |
# File 'lib/ronin/db/port.rb', line 38 attribute :id, :integer |
#ip_addresses ⇒ Array<IPAddress>
The IP Addresses that that have this port open.
79 |
# File 'lib/ronin/db/port.rb', line 79 has_many :ip_addresses, through: :open_ports |
#notes ⇒ Array<Note>
The associated notes.
95 |
# File 'lib/ronin/db/port.rb', line 95 has_many :notes, dependent: :destroy |
#number ⇒ Integer
The port number.
51 |
# File 'lib/ronin/db/port.rb', line 51 attribute :number, :integer |
#open_ports ⇒ Array<OpenPort>
The open ports.
71 |
# File 'lib/ronin/db/port.rb', line 71 has_many :open_ports, dependent: :destroy |
#protocol ⇒ "tcp", "udp"
The protocol of the port (either 'tcp'
/ 'udp'
).
44 |
# File 'lib/ronin/db/port.rb', line 44 enum :protocol, {tcp: 'tcp', udp: 'udp'}, default: :tcp |
#services ⇒ Array<Service>
The services that that use this port.
87 |
# File 'lib/ronin/db/port.rb', line 87 has_many :services, through: :open_ports |
Class Method Details
.import(number) ⇒ Port
Creates a new Port.
199 200 201 |
# File 'lib/ronin/db/port.rb', line 199 def self.import(number) create(number: number) end |
.lookup(number) ⇒ Port?
Looks up a port by it's number.
184 185 186 |
# File 'lib/ronin/db/port.rb', line 184 def self.lookup(number) find_by(number: number) end |
.with_ip_address(address) ⇒ Array<Port>
Queries all ports associated with the IP address.
165 166 167 168 169 170 171 |
# File 'lib/ronin/db/port.rb', line 165 def self.with_ip_address(address) joins(open_ports: :ip_address).where( open_ports: { ronin_ip_addresses: {address: address} } ) end |
.with_number(number) ⇒ Array<Port>
Queries all ports with the port number or in the port range.
110 111 112 |
# File 'lib/ronin/db/port.rb', line 110 def self.with_number(number) where(number: number) end |
.with_protocol(protocol) ⇒ Array<Port>
Queries all ports with the protocol.
127 128 129 |
# File 'lib/ronin/db/port.rb', line 127 def self.with_protocol(protocol) where(protocol: protocol) end |
.with_service_name(name) ⇒ Array<Port>
Queries all ports associated with the service name.
144 145 146 147 148 149 150 |
# File 'lib/ronin/db/port.rb', line 144 def self.with_service_name(name) joins(open_ports: :service).where( open_ports: { ronin_services: {name: name} } ) end |
Instance Method Details
#to_i ⇒ Integer
Converts the port to an integer.
211 212 213 |
# File 'lib/ronin/db/port.rb', line 211 def to_i self.number.to_i end |
#to_s ⇒ String
Converts the port to a string.
223 224 225 |
# File 'lib/ronin/db/port.rb', line 223 def to_s "#{self.number}/#{self.protocol}" end |