# Skipping Google search results that point to certain sites

I have the following code that will skip certain URLs if needed:

SEARCH = "inurl:index.php?id="

def get_urls
puts "Searching for possible SQL vulnerable sites, using search query #{SEARCH}"
agent = Mechanize.new
agent.user_agent = @user_agent
str_list = str.split(%r{=|&})
urls = str_list[1]
next if str_list[1].split('/')[2] == 'search.clearch.org'
next if str_list[1].split('/')[2] == 'duckfm.net'
next if str_list[1].split('/')[2] == 'search1.speedbit.com'
next if str_list[1].split('/')[2] == 'yoursearch.me'
next if str_list[1].split('/')[2] == 'search.speedbit.com'
next if str_list[1].split('/')[2] == 'www.sa-k.net'
next if str_list[1].split('/')[2] == 'github.com'
next if str_list[1].split('/')[2] == 'stackoverflow.com'
urls_to_log = URI.decode(urls)
puts "Site found: #{urls_to_log}"
sleep(1)
File.open("#{PATH}/SQL_sites_to_check.txt", 'a+') { |s| s.puts("#{urls_to_log}'") }
end
end
puts "Possible vulnerable sites dumped into #{PATH}/SQL_sites_to_check.txt"
end


Is there a better more readable, less smelly, way to write the next if's?

• instead of str_list[1].split('/')[2] 100 times, just assign str_list[1].split('/')[2] to a variable. Apr 7, 2016 at 18:16
• @BlueEyedBehemoth But then I'd still have to use the variable 100 times. Apr 7, 2016 at 18:23
• that's true, but you won't be executing a split that many times. You can also create an array of websites and just make sure that the variable(your URL) isn't in that array. Unfortunately I don't know ruby so I can't give you a complete answer. Apr 7, 2016 at 19:25
• @BlueEyedBehemoth Well, I guess I'll just stick with it as is for now, and figure something out, thanks for the ideas! Apr 7, 2016 at 19:39

You seem to be referring to the same information str_list[1].split('/')[2] several times. I highly suggest you simply do this one type and assign it to a variable so that your list can go

next if url == "github.com"

Also right at the top you have urls = str_list[1] but then you don't use that variable??
• And figure out if it was https or http Apr 7, 2016 at 18:17