Skip to content

Commit

Permalink
Update the powershell method for getting the WSL IP address.
Browse files Browse the repository at this point in the history
The previous method could return multiple IP addresses. The new method will specifically get the IP address for the eth0 network adapter.
  • Loading branch information
patrickcarlohickman committed Apr 5, 2023
1 parent 4d7fceb commit 43a021c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/add-host.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (!$PSBoundParameters.ContainsKey('wslHost')) {
$file = $env:windir + '\System32\drivers\etc\hosts'

# Get the current IP address of the wsl instance.
$wslIp = $(wsl -e hostname -I)
$wslIp = $(wsl -e /bin/bash -c "ip -4 -o address show eth0 | grep -oP """"(?<=inet\s)\d+(\.\d+){3}""""")

# Read the last byte of the file.
$size = 1
Expand Down
2 changes: 1 addition & 1 deletion bin/update-hosts-ips.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $file = $env:windir + '\System32\drivers\etc\hosts'
$regex = '(?<=^\s*)(\d+\.\d+\.\d+\.\d+)(?=.*\.' + $wslTld + '(\s+|$))'

# Get the current IP address of the wsl instance.
$wslIp = $(wsl -e hostname -I).Trim()
$wslIp = $(wsl -e /bin/bash -c "ip -4 -o address show eth0 | grep -oP """"(?<=inet\s)\d+(\.\d+){3}""""")

Write-Host "Updating hosts file for TLD [.$wslTld] with WSL IP [$wslIp]."

Expand Down

0 comments on commit 43a021c

Please sign in to comment.