Skip to content

Instantly share code, notes, and snippets.

@bugparty
Forked from mangege/check_unicom_cache.rb
Created October 31, 2016 16:01
Show Gist options
  • Save bugparty/c8f75b3475bb3defa548790e6e583b12 to your computer and use it in GitHub Desktop.
Save bugparty/c8f75b3475bb3defa548790e6e583b12 to your computer and use it in GitHub Desktop.
检查有效的联通缓存服务器ip
require 'uri'
require 'net/http'
require 'timeout'
def check_server(ip)
uri = URI('http://ip.mangege.com/')
Timeout::timeout(3) do
Net::HTTP.start(ip, 80) do |http|
request = Net::HTTP::Get.new uri
response = http.request request
puts ip if response.body.include?(ip)
end
end
rescue
end
(1..254).each do |i|
check_server("120.52.72.#{i}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment