module Masscan::Parsers::PlainText

Common methods for parsing plain-text data.

@api private

Constants

APP_PROTOCOLS

Mapping of application protocol names to their keywords.

IP_PROTOCOLS

Mapping of IP protocol names to their keywords.

REASONS
STATUSES

Mapping of status strings to their keywords.

Public Instance Methods

parse_app_protocol(proto) click to toggle source

Parses an application protocol name.

@param [String] proto

The application protocol name.

@return [Symbol, String]

The IP protocol keyword or a String if the application protocol wasn't
in {APP_PROTOCOLS}.
# File lib/masscan/parsers/plain_text.rb, line 120
def parse_app_protocol(proto)
  APP_PROTOCOLS[proto] || proto
end
parse_ip(ip) click to toggle source

Parses an IP address.

@param [String] ip

The string representation of the IP address.

@return [IPAddr]

The parsed IP address.
# File lib/masscan/parsers/plain_text.rb, line 146
def parse_ip(ip)
  IPAddr.new(ip)
end
parse_ip_protocol(proto) click to toggle source

Parses an IP protocol name.

@param [String] proto

The IP protocol name.

@return [:tcp, :udp, :icmp, :sctp, String]

The IP protocol keyword or a String if the IP protocol wasn't in
{IP_PROTOCOLS}.
# File lib/masscan/parsers/plain_text.rb, line 72
def parse_ip_protocol(proto)
  IP_PROTOCOLS[proto] || proto
end
parse_reason(reason) click to toggle source

Parses a reason string.

@param [String] reason

The reason string to parse.

@return [Array<:fin, :syn, :rst, :psh, :ack, :urg, :ece, :cwr>]

The reason keywords or a String if the flag wasn't in {REASONS}.
# File lib/masscan/parsers/plain_text.rb, line 48
def parse_reason(reason)
  flags = reason.split('-')
  flags.map! { |flag| REASONS[flag] || flag }
  flags
end
parse_status(status) click to toggle source

Parses a status string.

@param [String] status

The status string to parse.

@return [:open, :closed, String]

The status keyword or a String if the status wasn't in {STATUSES}.
# File lib/masscan/parsers/plain_text.rb, line 24
def parse_status(status)
  STATUSES[status] || status
end
parse_timestamp(timestamp) click to toggle source

Parses a timestamp.

@param [String] timestamp

The numeric timestamp value.

@return [Time]

The parsed timestamp value.
# File lib/masscan/parsers/plain_text.rb, line 133
def parse_timestamp(timestamp)
  Time.at(timestamp.to_i)
end