Class: Jah::Netstat

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/jah/commands/netstat.rb

Constant Summary

Constants included from Command

Command::COMM

Class Method Summary collapse

Methods included from Command

find, included

Class Method Details

.connectionsObject



20
21
22
23
24
25
# File 'lib/jah/commands/netstat.rb', line 20

def connections
  `netstat -ntu | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr`.to_a.map do |l|
    count, ip = l.split
    [ip, count]
  end
end

.countObject



16
17
18
# File 'lib/jah/commands/netstat.rb', line 16

def count
  `netstat -n | grep -i established | wc -l`.to_i
end

.netObject



8
9
10
11
12
13
14
# File 'lib/jah/commands/netstat.rb', line 8

def net
  out = ""
  connections.each do |c|
    out << "#{c[0]} => #{c[1]} connections\n"
  end
  out << "Total: #{Net.count}"
end