Created
July 10, 2012 04:22
-
-
Save tatiC/3080993 to your computer and use it in GitHub Desktop.
Free ports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# aliases | |
# alias scripts="cd /Users/tatic/Dropbox/my_projects/myscripts; ls -la" | |
# alias freeports="scripts;ports >> ports.txt;ruby freeports.rb;rm ports.txt" | |
# by: TatiCarvalho 2012 | |
# In the command-line: freeports | |
# v1.1 | |
# example: | |
# all_ports = ["3000", "3001"] | |
# busy_ports = ["3000", "3010"] | |
# free_port: ["3000", "3001"] - ["3000", "3010"] | |
busy_ports = [] | |
f = File.open("ports.txt") | |
f.each do |line| | |
busy_ports << /TCP *....../.match(line).to_s.gsub("TCP *:", "") | |
end | |
all_ports = ["3000", "3001", "3002", "3003", "3004", "3005", "3006", "3007", "3008", "3009", "3010"] | |
free_port = (all_ports - busy_ports).first | |
puts "Free port: #{free_port}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment