Module: Masscan::Parsers::PlainText Private

Included in:
JSON, List
Defined in:
lib/masscan/parsers/plain_text.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Common methods for parsing plain-text data.

Constant Summary collapse

STATUSES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Mapping of status strings to their keywords.

{
  'open'   => :open,
  'closed' => :closed
}
REASONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  'fin' => :fin,
  'syn' => :syn,
  'rst' => :rst,
  'psh' => :psh,
  'ack' => :ack,
  'urg' => :urg,
  'ece' => :ece,
  'cwr' => :cwr
}
IP_PROTOCOLS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Mapping of IP protocol names to their keywords.

{
  'tcp'  => :tcp,
  'udp'  => :udp,
  'icmp' => :icmp,
  'sctp' => :sctp
}
APP_PROTOCOLS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Mapping of application protocol names to their keywords.

{
  "ssh1" => :ssh1,
  "ssh2" => :ssh2,
  "ssh"  => :ssh,
  "http" => :http,
  "ftp"  => :ftp,
  "dns-ver" => :dns_ver,
  "snmp" => :smtp,
  "nbtstat" => :nbtstat,
  "ssl" => :ssl3,
  "smtp" => :smtp,
  "smb" => :smb,
  "pop" => :pop,
  "imap" => :imap,
  "X509" => :x509,
  "zeroaccess" => :zeroaccess,
  "title" => :html_title,
  "html" => :html,
  "ntp" => :ntp,
  "vuln" => :vuln,
  "heartbleed" => :heartbleed,
  "ticketbleed" => :ticketbleed,
  "vnc" => :vnc,
  "safe" => :safe,
  "memcached" => :memcached,
  "scripting" => :scripting,
  "versioning" => :versioning,
  "coap"        => :coap,
  "telnet"      => :telnet,
  "rdp"         => :rdp,
  "http.server" => :http_server
}

Instance Method Summary collapse

Instance Method Details

#parse_app_protocol(proto) ⇒ Symbol, String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses an application protocol name.

Parameters:

  • proto (String)

    The application protocol name.

Returns:

  • (Symbol, String)

    The IP protocol keyword or a String if the application protocol wasn't in APP_PROTOCOLS.



122
123
124
# File 'lib/masscan/parsers/plain_text.rb', line 122

def parse_app_protocol(proto)
  APP_PROTOCOLS[proto] || proto
end

#parse_ip(ip) ⇒ IPAddr

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses an IP address.

Parameters:

  • ip (String)

    The string representation of the IP address.

Returns:

  • (IPAddr)

    The parsed IP address.



148
149
150
# File 'lib/masscan/parsers/plain_text.rb', line 148

def parse_ip(ip)
  IPAddr.new(ip)
end

#parse_ip_protocol(proto) ⇒ :tcp, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses an IP protocol name.

Parameters:

  • proto (String)

    The IP protocol name.

Returns:

  • (:tcp, :udp, :icmp, :sctp, String)

    The IP protocol keyword or a String if the IP protocol wasn't in IP_PROTOCOLS.



74
75
76
# File 'lib/masscan/parsers/plain_text.rb', line 74

def parse_ip_protocol(proto)
  IP_PROTOCOLS[proto] || proto
end

#parse_reason(reason) ⇒ Array<:fin, :syn, :rst, :psh, :ack, :urg, :ece, :cwr>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses a reason string.

Parameters:

  • reason (String)

    The reason string to parse.

Returns:

  • (Array<:fin, :syn, :rst, :psh, :ack, :urg, :ece, :cwr>)

    The reason keywords or a String if the flag wasn't in REASONS.



50
51
52
53
54
# File 'lib/masscan/parsers/plain_text.rb', line 50

def parse_reason(reason)
  flags = reason.split('-')
  flags.map! { |flag| REASONS[flag] || flag }
  flags
end

#parse_status(status) ⇒ :open, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses a status string.

Parameters:

  • status (String)

    The status string to parse.

Returns:

  • (:open, :closed, String)

    The status keyword or a String if the status wasn't in STATUSES.



26
27
28
# File 'lib/masscan/parsers/plain_text.rb', line 26

def parse_status(status)
  STATUSES[status] || status
end

#parse_timestamp(timestamp) ⇒ Time

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses a timestamp.

Parameters:

  • timestamp (String)

    The numeric timestamp value.

Returns:

  • (Time)

    The parsed timestamp value.



135
136
137
# File 'lib/masscan/parsers/plain_text.rb', line 135

def parse_timestamp(timestamp)
  Time.at(timestamp.to_i)
end