-
Notifications
You must be signed in to change notification settings - Fork 0
refactor get_host_ip method to use route for host IP detection #20
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+9
|
||||||||||||||||||||||||||||||||||||
| # 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 | |
| # This uses `route` to find the host's default network interface | |
| # and then `ipconfig getifaddr` to get a single IPv4 address | |
| # for that interface on macOS. | |
| interface = `route -n get default | awk '/interface:/{print $2}'`.strip | |
| host_ip = "" | |
| unless interface.empty? | |
| host_ip = `ipconfig getifaddr #{interface}`.strip | |
| end | |
| if host_ip.nil? || host_ip.empty? | |
| raise "Unable to determine host IP address for SMB mount. Please configure smb_host_ip manually in the Vagrantfile." | |
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s trailing whitespace at the end of these comment lines; please remove it to avoid churn in diffs and whitespace-only changes.