2013-04-08 22:30:41 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module GuestLinux
|
|
|
|
module Cap
|
|
|
|
class ReadIPAddress
|
|
|
|
def self.read_ip_address(machine)
|
2017-12-28 19:31:04 +00:00
|
|
|
|
|
|
|
comm = machine.communicate
|
|
|
|
|
|
|
|
if comm.test("test -f /sbin/ip")
|
|
|
|
command = "LANG=en ip addr | grep -Po 'inet \\K[\\d.]+' | grep -v 127.0.0.1"
|
|
|
|
else
|
|
|
|
command = "LANG=en ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1 }'"
|
|
|
|
end
|
|
|
|
|
2013-04-08 22:30:41 +00:00
|
|
|
result = ""
|
2017-12-28 19:31:04 +00:00
|
|
|
comm.sudo(command) do |type, data|
|
2013-04-08 22:30:41 +00:00
|
|
|
result << data if type == :stdout
|
|
|
|
end
|
|
|
|
|
2013-06-09 20:27:08 +00:00
|
|
|
result.chomp.split("\n").first
|
2013-04-08 22:30:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|