You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
Crystal
57 lines
1.3 KiB
Crystal
5 years ago
|
require "../modules/record_helpers"
|
||
|
|
||
|
class LtnpRecord
|
||
5 years ago
|
getter proto : String
|
||
5 years ago
|
getter state : String
|
||
|
getter address : String
|
||
|
getter port : String
|
||
|
getter f_address : String
|
||
|
getter f_port : String
|
||
|
getter state : String
|
||
|
getter pid : String
|
||
|
getter p_name : String
|
||
|
|
||
5 years ago
|
def initialize(record : String)
|
||
5 years ago
|
ser_record = RecordHelpers.clean_record(record)
|
||
|
@proto = ser_record[0]
|
||
|
@address, @port = ser_address_port ser_record[3].split(':')
|
||
|
@f_address, @f_port = ser_address_port ser_record[4].split(':')
|
||
|
@state = ser_record[5]
|
||
|
@pid, @p_name = ser_pid_p_name ser_record[6]
|
||
5 years ago
|
end
|
||
|
|
||
|
def to_s
|
||
5 years ago
|
puts "%s, " * 8 % [
|
||
|
@proto, @state, @address, @port,
|
||
|
@f_address, @f_port, @pid, @p_name,
|
||
|
]
|
||
5 years ago
|
end
|
||
|
|
||
5 years ago
|
def output_s
|
||
5 years ago
|
"Port: %s, Process: %s, Process ID: %s" % [self.port, self.p_name, self.pid]
|
||
|
end
|
||
|
|
||
5 years ago
|
def ser_address_port(address_port : Array) : {String, String}
|
||
5 years ago
|
address = String.new
|
||
|
port = String.new
|
||
|
unless address_port.size > 2
|
||
|
address = address_port[0]
|
||
|
port = address_port[1]
|
||
|
else
|
||
|
port = address_port[-1]
|
||
|
end
|
||
|
{address, port}
|
||
5 years ago
|
end
|
||
|
|
||
|
def ser_pid_p_name(pid_pro_str : String) : {String, String}
|
||
5 years ago
|
pid = String.new
|
||
|
p_name = String.new
|
||
|
unless pid_pro_str == "-"
|
||
|
pid_pro = pid_pro_str.split('/')
|
||
|
pid = pid_pro[0]
|
||
|
p_name = pid_pro[1]
|
||
|
end
|
||
|
{pid, p_name}
|
||
5 years ago
|
end
|
||
|
end
|