SoFunction
Updated on 2025-03-09

Ruby implements modification of hosts under ubuntu

Under Windows, we know where to modify the hosts file, but in the ubuntu system, there are other systems, such as Android phones. Perhaps there are not so many small software for you to simply modify. Let's write it yourself.

#!/usr/bin/ruby
#coding=utf-8
require 'open-uri'

url= "http :// /vokins/simpleu/master/hosts"

begin
 open("/etc/hosts","w") do |x|
   open(url).read
 end
rescue Errno::EACCES
 puts "Need root? "
 exec "sudo ruby " + $0 + (' ')
end
puts "Write hosts success!"

The above is all about this article. I hope you like it