Created
October 3, 2011 07:59
-
-
Save watson/1258660 to your computer and use it in GitHub Desktop.
Use this shell-script to change your DNS servers to the European Unblock-US servers via one simple command. Requires the 'open4' gem.
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 | |
begin | |
require 'rubygems' if RUBY_VERSION =~ /^1\.8/ | |
require 'open4' | |
rescue LoadError | |
puts "Please install the `open4` gem" | |
exit 1 | |
end | |
# Get the primary service ID | |
status = Open4::popen4("scutil") do |pid, stdin, stdout, stderr| | |
stdin.puts "open" | |
stdin.puts "get State:/Network/Global/IPv4" | |
stdin.puts "d.show" | |
stdin.puts "quit" | |
stdin.close | |
@@primary_service_id = stdout.read.match(/PrimaryService : ([\dA-F-]+)/)[1] | |
end | |
# Set the DNS servers for the primary service ID | |
status = Open4::popen4("sudo scutil") do |pid, stdin, stdout, stderr| | |
stdin.puts "open" | |
stdin.puts "d.init" | |
stdin.puts "d.add ServerAddresses * 109.123.80.171 62.75.155.146" | |
stdin.puts "set State:/Network/Service/#{@@primary_service_id}/DNS" | |
stdin.puts "quit" | |
stdin.close | |
end | |
# List the current nameservers | |
status = Open4::popen4("scutil") do |pid, stdin, stdout, stderr| | |
stdin.puts "open" | |
stdin.puts "get State:/Network/Service/#{@@primary_service_id}/DNS" | |
stdin.puts "d.show" | |
stdin.puts "quit" | |
stdin.close | |
dictionary = stdout.read | |
puts "The current nameservers are: %s and %s" % [ | |
dictionary.match(/0 : ([\d\.]+)/)[1], | |
dictionary.match(/1 : ([\d\.]+)/)[1] | |
] | |
end | |
system 'open http://check.unblock-us.com/' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment