Skip to content

Instantly share code, notes, and snippets.

@natew
Created September 10, 2013 22:02
Show Gist options
  • Save natew/6516368 to your computer and use it in GitHub Desktop.
Save natew/6516368 to your computer and use it in GitHub Desktop.
Copy /etc/hosts and replace with public IP, for quickly setting up the hosts file on a windows VM
#!/usr/bin/ruby
require 'socket'
ip = Socket.ip_address_list.detect { |intf| intf.ipv4? and !intf.ipv4_loopback? }.ip_address
puts "ip: #{ip}"
IO.popen('pbcopy', 'w') do |f|
f << File.read('/etc/hosts').gsub!(/.*127.*localhost/im, '').gsub!(/127\.0\.0\.1/im, ip)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment