Module: Gobuster::Parsers::Dir

Defined in:
lib/gobuster/parsers/dir.rb

Class Method Summary collapse

Class Method Details

.parse(io) {|response| ... } ⇒ Enumerator

Parses gobuster dir output.

Parameters:

  • io (IO)

    The IO stream to parse.

Yields:

  • (response)

    The given block will be passed each parsed response.

Yield Parameters:

  • response (Response)

    The parsed response.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator will be returned.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gobuster/parsers/dir.rb', line 21

def self.parse(io)
  return enum_for(__method__,io) unless block_given?

  line_regexp = /^(\/[^\s]+)\s+\(Status: (\d{3})\)\s+\[Size: (\d+)\]/

  io.each_line do |line|
    if (match = line.match(line_regexp))
      yield Response.new(
        path:   match[1],
        status: match[2].to_i,
        size:   match[3].to_i
      )
    end
  end
end