Skip to main content
Fix code sample
Source Link

Unless you are trying to parse arbitrary hosts files why not use the built in IP libraries?

require 'ipaddr'
...
ip_address = IPSocket.getaddress('d.podomatic.com'hostname)

You could also look at this vagrant add-in: https://github.com/cogitatio/vagrant-hostsupdater This might work too https://github.com/devopsgroup-io/vagrant-hostmanager though I haven't looked at it in depth.

Just a note with your code: you should probably check for commented out lines in your hosts file (at least if it looks anything like mine)

Unless you are trying to parse arbitrary hosts files why not use the built in IP libraries?

require 'ipaddr'
...
ip_address = IPSocket.getaddress('d.podomatic.com')

You could also look at this vagrant add-in: https://github.com/cogitatio/vagrant-hostsupdater This might work too https://github.com/devopsgroup-io/vagrant-hostmanager though I haven't looked at it in depth.

Just a note with your code: you should probably check for commented out lines in your hosts file (at least if it looks anything like mine)

Unless you are trying to parse arbitrary hosts files why not use the built in IP libraries?

require 'ipaddr'
...
ip_address = IPSocket.getaddress(hostname)

You could also look at this vagrant add-in: https://github.com/cogitatio/vagrant-hostsupdater This might work too https://github.com/devopsgroup-io/vagrant-hostmanager though I haven't looked at it in depth.

Just a note with your code: you should probably check for commented out lines in your hosts file (at least if it looks anything like mine)

Source Link

Unless you are trying to parse arbitrary hosts files why not use the built in IP libraries?

require 'ipaddr'
...
ip_address = IPSocket.getaddress('d.podomatic.com')

You could also look at this vagrant add-in: https://github.com/cogitatio/vagrant-hostsupdater This might work too https://github.com/devopsgroup-io/vagrant-hostmanager though I haven't looked at it in depth.

Just a note with your code: you should probably check for commented out lines in your hosts file (at least if it looks anything like mine)