Merge pull request #3 from BraydonKains/kill_process

Added ability to kill process found on port
pull/5/head
Braydon Kains 5 years ago committed by GitHub
commit 8aee1e9788
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,16 +13,18 @@ Show help menu.
### -c PORT, --check-port=PORT
Get the name and process ID of the process running on a given port
### -k PORT, --kill-port=PORT
Check the process running on a given port with the option to kill it if you'd like.
## TODO
- [] Add the ability to kill process on port
- [] Maybe look into other cli operations? (getting IP?)
- [] Come up with other useful stuff
- [] Write up contributors guide
- [] Decide how to do documentation (probably Github wiki?)
- [] Write man page (figure out how to do that lol)
- [] Figure out distribution/release
- [x] Set up CI (probably Travis)
* [x] Add the ability to kill process on port
* [] Maybe look into other cli operations? (getting IP?)
* [] Come up with other useful stuff
* [] Write up contributors guide
* [] Decide how to do documentation (probably Github wiki?)
* [] Write man page (figure out how to do that lol)
* [] Figure out distribution/release
* [x] Set up CI (probably Travis)
## Contributing
I don't know that I'm ready for contributors yet because I don't have a good contributors guide. I do plan to eventually open this up to contributors. If you have any ideas for future operations, please feel free to open an issue, I am happy to discuss ideas!

@ -1,6 +1,6 @@
require "option_parser"
require "./ltnp/ltnp_operator"
require "./modules/netstat_runner"
require "./modules/command_runner"
OptionParser.parse do |parser|
parser.banner = "Welcome to eznetstat!"
@ -16,19 +16,35 @@ OptionParser.parse do |parser|
end
parser.on "-c PORT", "--check-port=PORT", "Get the process name and ID of process on port" do |port|
ltnp_operator = NetstatRunner.run_ltnp
ltnp_operator = CommandRunner.run_ltnp
record = ltnp_operator.get_port_record port
unless record.nil?
puts "Port: %s, Process: %s" % [record.port, record.p_name]
puts "Port: %s, Process: %s, Process ID: %s" % [record.port, record.p_name, record.pid]
else
puts "No processes found on port %s" % port
end
exit
end
parser.on "-k", "--kill-port", "Kill process on port" do
ltnp_operator = NetstatRunner.run_ltnp
ltnp_operator.say_hi
parser.on "-k PORT", "--kill-port=PORT", "Kill process on port" do |port|
ltnp_operator = CommandRunner.run_ltnp
record = ltnp_operator.get_port_record port
unless record.nil?
puts "Port: %s, Process: %s, Process ID: %s" % [record.port, record.p_name, record.pid]
puts "Would you like to kill %s? (y/n)" % [record.p_name]
input = gets
unless input.nil?
if input.downcase == "y"
CommandRunner.run_kill record.pid
end
end
else
puts "No processes found on port %s" % port
end
exit
end
end

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

@ -1,7 +0,0 @@
module NetstatRunner
def self.run_ltnp : LtnpOperator
io = IO::Memory.new
Process.run("sudo netstat -ltnp", shell: true, output: io)
LtnpOperator.new io.to_s
end
end
Loading…
Cancel
Save