Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-detection capibility #112

Closed
estahn opened this issue Mar 18, 2015 · 1 comment
Closed

Auto-detection capibility #112

estahn opened this issue Mar 18, 2015 · 1 comment

Comments

@estahn
Copy link

estahn commented Mar 18, 2015

Hi @tmatilai,

Would it be possible to have some sort of proxy auto-detection added?

Example:

  if Vagrant.has_plugin?("vagrant-proxyconf") && proxy_running?
    vagrant.proxy.autodetect = true
    vagrant.proxy.autodetect_port = 8123
  end

I'm using @fnicols snippet in my Vagrantfile: https://gist.github.com/fnichol/7551540

require 'socket'

# @return [String] public IP address of workstation used for egress traffic
def local_ip
  @local_ip ||= begin
                  # turn off reverse DNS resolution temporarily
    orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true

    UDPSocket.open do |s|
      s.connect '64.233.187.99', 1 # a google IP, does not hit network
      s.addr.last
    end
  ensure
    Socket.do_not_reverse_lookup = orig
  end
end

# @return [Integer] default polipo listening port
def local_port ; 8123 ; end

# @return [String] the polipo proxy URL
def http_proxy_url ; "http://#{local_ip}:#{local_port}" ; end

# @return [TrueClass,FalseClass] whether or not the polipo port is listening
def proxy_running?
  socket = TCPSocket.new(local_ip, local_port)
  true
rescue SocketError, Errno::ECONNREFUSED,
    Errno::EHOSTUNREACH, Errno::ENETUNREACH, IOError
  false
rescue Errno::EPERM, Errno::ETIMEDOUT
  false
ensure
  socket && socket.close
end

Further down:

  if Vagrant.has_plugin?("vagrant-proxyconf") && proxy_running?
    vagrant.proxy.http     = http_proxy_url
    vagrant.proxy.https    = http_proxy_url
    vagrant.proxy.no_proxy = "localhost,127.0.0.1,.example.com"
  end

Would be nice to have this in the plugin already and a cleaner Vagrantfile.

Enrico

@estahn
Copy link
Author

estahn commented Mar 20, 2015

Duplicate of #38

@estahn estahn closed this as completed Mar 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant