Last active
June 30, 2019 12:32
-
-
Save bcoles/af5ac8f75a3fde42f397f53e9069b27c to your computer and use it in GitHub Desktop.
Reverse /etc/services
This file contains hidden or 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
#!/usr/bin/env ruby | |
# Reverse /etc/services | |
# Returns Hash of services and ports with service names as Hash keys | |
services = {} | |
File.read('/etc/services').each_line do |line| | |
next if line.strip == '' # remove blank lines | |
next if line.start_with?('#') # remove comment lines | |
if line =~ /([^\s]+)\s+(\d+\/[udptcp]{3})/ | |
service = $1.to_sym | |
port = $2 | |
if services.include?(service) | |
services[service] << port | |
else | |
services[service] = [port] | |
end | |
end | |
end | |
puts 'Examples:' | |
puts "* Telnet: #{services[:telnet].join(', ')}" | |
puts "* SSH: #{services[:ssh].join(', ')}" | |
puts "* DNS: #{services[:domain].join(', ')}" | |
#puts services.inspect |
Author
bcoles
commented
Apr 21, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment