Skip to content

Instantly share code, notes, and snippets.

@jamesmoriarty
Created December 22, 2010 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmoriarty/751267 to your computer and use it in GitHub Desktop.
Save jamesmoriarty/751267 to your computer and use it in GitHub Desktop.
Vpn assigned dns override script.
#!/usr/bin/env ruby
require 'pty'
require 'optparse'
unless ENV['USER'].eql?("root")
puts "Must be run as root.\nFailed."
exit
end
options = {}
optparse = OptionParser.new do|opts|
opts.banner = "Sets VPN assigned DNS server address from 10.1.0.252 to 10.1.0.251 on OSX."
options[:verbose] = false
opts.on( '-v', '--verbose', 'Output more information' ) do
options[:verbose] = true
end
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
optparse.parse!
scutil = PTY.spawn("scutil") do |output, input, pid|
puts "Setting..."
Thread.abort_on_exception = true
thread = Thread.new do
output.each do |line|
if line.include?("denied")
puts "Failed."
exit
end
puts line if options[:verbose]
end
end
input.write("list State:/Network/Service/[^/]+/DNS\n")
input.write("show State:/Network/Service/com.cisco.VPN/DNS\n")
input.write("d.init\n")
input.write("get State:/Network/Service/com.cisco.VPN/DNS\n")
input.write("d.show\n")
input.write("d.add ServerAddresses * 10.1.0.251\n")
input.write("d.show\n")
input.write("set State:/Network/Service/com.cisco.VPN/DNS\n")
input.write("exit\n")
puts "Done."
thread.join(0.5)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment