Class: Net::SSH::Locate::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/net/ssh/locate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#agentPIDObject (readonly)

Returns the value of attribute agentPID.



81
82
83
# File 'lib/net/ssh/locate.rb', line 81

def agentPID
  @agentPID
end

#agentSocketObject (readonly)

Returns the value of attribute agentSocket.



81
82
83
# File 'lib/net/ssh/locate.rb', line 81

def agentSocket
  @agentSocket
end

#foundObject (readonly)

Returns the value of attribute found.



81
82
83
# File 'lib/net/ssh/locate.rb', line 81

def found
  @found
end

Instance Method Details

#found?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/net/ssh/locate.rb', line 101

def found?
  @found
end

#scanObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/net/ssh/locate.rb', line 83

def scan
  @found = false
  procs = Sys::ProcTable.ps(smaps: false, cgroup: false).select do
    |p|
    res = p.cmdline =~ /ssh-agent/ && p.cmdline !~ /--session=ubuntu/ && p.state != 'Z'
    res
  end
  return if procs.empty?

  p = procs.first
  p.cmdline =~ /ssh-agent\s-a ([-.a-zA-Z0-9_\/]+)/
  return unless $LAST_MATCH_INFO

  @found = true
  @agentSocket = $LAST_MATCH_INFO[1]
  @agentPID = p.pid
end