Created
April 4, 2014 20:05
-
-
Save alexdantas/9982166 to your computer and use it in GitHub Desktop.
Shows all valid hosts on a Windows machine
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
# This is where it all starts and ends | |
begin | |
# It saves all the lines of the file inside | |
# the 'contents' variable. | |
# Note that we use '/' as the path separator | |
# (and not '\') | |
contents = File.read("C:/Windows/system32/drivers/etc/hosts") | |
# We're going through each line of 'contents', | |
# assigning one at a time to the 'line' variable. | |
contents.each_line do |line| | |
# For each 'line', we'll show it if it's | |
# not a comment. | |
puts line if not line.match(/^\s*#/) | |
# 'puts' shows stuff on the screen. | |
# 'match' compares the string to a Regular Expression. | |
# | |
# Idk if you know what those are, but think of | |
# them as indicators of what should be on a string. | |
# | |
# That '/^\s*#/' is trying to see if the string 'line' | |
# * Begins the line (^) with zero spaces or more (\s*) | |
# * Has a '#' after them (#) | |
end | |
# And that's it! | |
exit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment