Compare commits

..

1 Commits

@ -0,0 +1,14 @@
# Am I going to use this? Probably not tbh
enum State
LISTEN
ESTABLISHED
SYN_SENT
SYN_RECV
LAST_ACK
CLOSE_WAIT
TIME_WAIT
CLOSED
CLOSING
FIN_WAIT1
FIN_WAIT2
end

@ -1,10 +1,18 @@
module CommandRunner module CommandRunner
# netstat
def self.run_ltnp : String def self.run_ltnp : String
io = IO::Memory.new io = IO::Memory.new
Process.run("netstat -ltnp", shell: true, output: io) Process.run("netstat -ltnp", shell: true, output: io)
io.to_s io.to_s
end end
def self.run_nat : String
io = IO::Memory.new
Process.run("netstat -nat", shell: true, output: io)
io.to_s
end
# kill
def self.run_kill(pid : String) : String def self.run_kill(pid : String) : String
io = IO::Memory.new io = IO::Memory.new
Process.run("kill #{pid}", shell: true, output: io) Process.run("kill #{pid}", shell: true, output: io)

@ -4,4 +4,32 @@ module RecordHelpers
tokenized_record = tokenized_record.reject { |s| s == "" } tokenized_record = tokenized_record.reject { |s| s == "" }
tokenized_record tokenized_record
end end
def ser_address_port(address_port_str : String) : {String, String}
address_port = address_port_str.split(':')
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}
end
def ser_pid_p_name(pid_pro_str : String) : {String, String}
pid_pro = pid_pro_str.split('/')
pid = String.new
p_name = String.new
if pid_pro.size == 2
pid = pid_pro[0]
p_name = pid_pro[1]
end
{pid, p_name}
end
end end

@ -0,0 +1,14 @@
require "../modules/command_runner"
require "../records/nat_record"
class NatOperator
def initialize(nat_data = "")
if nat_data.empty?
nat_data = CommandRunner.run_nat
end
records = nat_data.each_line
records = records.each.select(/^tcp/)
@nat_records = Array(NatRecord).new
records.each { |s| @nat_records << NatRecord.new s }
end
end

@ -12,45 +12,25 @@ class LtnpRecord
getter p_name : String getter p_name : String
def initialize(record : String) def initialize(record : String)
ser_record = RecordHelpers.clean_record(record) tok_record = RecordHelpers.clean_record(record)
@proto = ser_record[0]
@address, @port = ser_address_port ser_record[3].split(':') @proto = tok_record[0]
@f_address, @f_port = ser_address_port ser_record[4].split(':') @address, @port = RecordHelpers.ser_address_port(tok_record[3].split(':'))
@state = ser_record[5] @f_address, @f_port = RecordHelpers.ser_address_port(tok_record[4].split(':'))
@pid, @p_name = ser_pid_p_name ser_record[6] @state = tok_record[5]
@pid, @p_name = ser_pid_p_name tok_record[6]
end end
def to_s def to_s
puts "%s, " * 8 % [ puts "%s, " * 8 % [
@proto, @state, @address, @port, @proto, @state,
@f_address, @f_port, @pid, @p_name, @address, @port,
@f_address, @f_port,
@pid, @p_name
] ]
end end
def output_s def output_s
"Port: %s, Process: %s, Process ID: %s" % [self.port, self.p_name, self.pid] "Port: %s, Process: %s, Process ID: %s" % [self.port, self.p_name, self.pid]
end end
def ser_address_port(address_port : Array) : {String, String}
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}
end
def ser_pid_p_name(pid_pro_str : String) : {String, String}
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}
end
end end

@ -0,0 +1,33 @@
require "../modules/record_helpers"
class NatRecord
getter proto : String
getter recv_q : Int
getter send_q : Int
getter address : String
getter port
getter f_address : String
getter f_port : String
getter state : String
def initialize(record : String)
tok_record = RecordHelpers.clean_record(record)
@proto = tok_record[0]
@recv_q = tok_record[1].to_i
@send_q = tok_record[2].to_i
@address, @port = RecordHelpers.ser_address_port(tok_record[3])
@f_address, @f_port = RecordHelpers.ser_address_port(tok_record[4])
@state = tok_record[5]
end
def to_s
puts "%s, " * 8 % [
@proto,
@recv_q, @send_q,
@address, @port,
@f_address, @f_port,
@state
]
end
end

@ -5,9 +5,9 @@ authors:
- BraydonKains <kainsbraydon@gmail.com> - BraydonKains <kainsbraydon@gmail.com>
targets: targets:
main: eznet-cli:
main: ./eznet.cr eznet: ./main.cr
crystal: 0.34.0 crystal: 0.33.0
license: GPL-3.0 license: GPL-3.0

@ -0,0 +1,15 @@
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:27036 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:57343 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:60337 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:27060 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:57621 0.0.0.0:* LISTEN
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 192.168.0.36:45332 172.217.164.206:443 ESTABLISHED
tcp 0 0 192.168.0.36:36012 140.82.114.4:443 ESTABLISHED
tcp 0 0 192.168.0.36:39648 140.82.113.5:443 ESTABLISHED
tcp 0 0 192.168.0.36:35658 149.154.175.53:443 ESTABLISHED
tcp 1 0 192.168.0.36:56858 35.186.224.53:443 CLOSE_WAIT
tcp6 0 0 :::22 :::* LISTEN
Loading…
Cancel
Save