I have a VM with an operating system of Windows 11 running from a MacBook. What I would like to do is determine the IP Address of the MacBook (host) programmatically. I know I could just switch to the host and view it there but that would take the fun out of it.
Depending on which Network I connect to the IP Address will change.
Your suggestions are appreciated.
IP Address of Host
-
- GoldLounger
- Posts: 2640
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
IP Address of Host
Regards,
John
John
-
- GoldLounger
- Posts: 2640
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: IP Address of Host
If I use "Tracert" in a PowerShell script it will return the host IP Address. Here is the PSI script I am running. The script will map the Z-drive accordingly. What I need assistance with is automatically responding to "Press Enter to continue" and If the Z-drive is already mapped, disconnect it before trying to map it.
Your suggestions are appreciated.
Code: Select all
# Define the hostname of the host
$hostname = "YourHostComputerName"
# Run the traceroute command
$result = tracert $hostname
# Extract the IP address from the traceroute result
$ipAddress = ($result | Select-String -Pattern "\[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\]").Matches.Groups[1].Value
# Output the IP address
Write-Output "Host IP Address: $ipAddress"
# Map drive Z to the network path
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\$ipAddress\SomeFolderNameHere" -Persist
pause
Regards,
John
John