From 3821e7ad507f6117365cd4ff24e64c64de56a3da Mon Sep 17 00:00:00 2001 From: David Pollard Date: Tue, 10 Feb 2026 11:33:20 -0800 Subject: [PATCH] refactor get_host_ip method to use route for host IP detection --- Vagrantfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 570d09f..efbe9b8 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -2,8 +2,11 @@ # vi: set ft=ruby : def get_host_ip - # This example uses `ifconfig` and `grep` to find inet interface and host IP address - host_ip = `ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'`.strip + # This uses `route` to find the host's default IP address + # and pipes it through to `awk` and `ifconfig` + # to extract the IP address of the host machine. + host_ip = `route -n get default | awk '/interface:/{print $2}' | xargs ifconfig | awk '/inet / {print $2}'`.strip + return host_ip end