VMware Communities
vinayan3
Contributor
Contributor

Retrieve IP address using vmrun

I would like to retrieve the IP address of the VM I started up. When I had VIX on windows there was a way to retrieve this information by calling ReadVariable with the option VM_GUEST_VARIABLE. The variable name was 'ip'.

Is this possible with vmrun?

Thanks,

Vinay A.

0 Kudos
10 Replies
WoodyZ
Immortal
Immortal

0 Kudos
vinayan3
Contributor
Contributor

I looked at that and ran the following command

vmrun readVariable "Mac OS X Server 10.5.5.vmx" runtimeConfig ip

I get a blank line as output.

0 Kudos
WoodyZ
Immortal
Immortal

I looked at that and ran the following command

> vmrun readVariable "Mac OS X Server 10.5.5.vmx" runtimeConfig ip
> 

I get a blank line as output.

Okay so you looked but you need to RTFM.

For readVariable it states...

Reads a variable from the virtual machine state or guest.

You can get either runtime configuration in the .vmx file,

or environment variables in the guest operating system.

The latter requires a valid guest login.

<path to .vmx file> [ runtimeConfig|guestEnv ] <variable name>

So runtimeConfig reads the value of a parameter in the .vmx configuration file and "ip" is not a valid parameter.

If you want the IP Address of the Guest then you're going to need run a script on the guest to get it's IP Address and retrieve it by one means or another. Like setting it to an Environment Variable and the use readVariable with guestEnv or pipe it to a file and retrieve the file and process it accordingly.

0 Kudos
SoMoS
Contributor
Contributor

Anyway, if I can read a guest variable named "ip" with VIX like

IJob jobHandle = _vmHandle.ReadVariable(VixCOM.Constants.VIX_VM_GUEST_VARIABLE, "ip", 0, null);

Why (edited) If I do a

vmrun readVariable vmxFile guestEnv ip

I get an (edited) empty line?

Message was edited by: etung for language

0 Kudos
WoodyZ
Immortal
Immortal

It looks like "guestEnv" is the same as "VIX_GUEST_EVIROMENT_VARIABLE" in VIX  not "VIX_VM_GUEST_VARIABLE" and "ip" or "IP" is not a standard Windows Environmental Variable.

If you want to know what "guestEnv" will retrieve then type "set" (without quotes) in a Command Prompt and what is returned are the Environmental Variables that can be retrieved.

Or like I've previously said "If you want the IP Address of the Guest then you're going to need run a  script on the guest to get it's IP Address and retrieve it by one means  or another. Like setting it to an Environment Variable and the use  readVariable with guestEnv or pipe it to a file and retrieve the file  and process it accordingly."

BTW There is no good excuse for the language you've used so have a look at section 4 c in the VMware Community Terms of Use.

c. Do not use offensive language. If you have any doubts about whether a  particular statement might be considered offensive by other users, do  not post it.
0 Kudos
pajp
Contributor
Contributor

Hi,

while searching the web for the same thing I stumbled across this thread. I just wanted to leave a note for future searchers that the "readVariable <vmx> guestVar ip" command of vmrun can retreive the "ip" variable in VMWare Fusion with OS X Lion guests (and it contains the IP address of the guest system). Note that it's "guestVar", not "guestEnv".

0 Kudos
WoodyZ
Immortal
Immortal

pajp wrote: Note that it's "guestVar", not "guestEnv".

@pajp  For the record, at the time this thread took place in June of 2009 and March of 2011 the "guestVar" Parameter did not exist with vmrun and this now requires at least VIX API 1.11 which was not released until September 14 2011.  Also to avoid any confusion the "guestEnv" Parameter is still a valid Parameter for the scope at which it operates.

Like everything in IT while it ages rapidely and can become outdated nonetheless what was accurate and correct when this thread was started still is if one is not using at least VIX API 1.11.  So for anyone trying to use "guestVar" Parameter make sure you have at least VIX API 1.11 as it does not and will not work with previous versions.

0 Kudos
pajp
Contributor
Contributor

Yes, I'm aware that it's an old thread, that's the very reason I wanted to update it with up-to-date information, as it appeared when I googled the issue in question. Your clarification is useful, but I don't understand why you direct it at me. I did not mean to imply that anyone was wrong; I just shared what I have learned.

0 Kudos
WoodyZ
Immortal
Immortal

Regardless of your intensions the manner/style of what you presented gives the appearance to negate what was previously discussed.  A more accurate/proper way you could have added to this thread was to have pointed out that at the time this thread took place the "guestVar" parameter did not exist with vmrun and currently requires at least VIX API 1.11 to use it with vmrun, instead of phrasing your comments as you did.  Not everyone upgrades (or even can in some cases) to the latest releases of whatever, so it's very important to qualify statements when adding to existing and dated threads when what's being added contradicts (still) valid information! Smiley Wink

0 Kudos
pajp
Contributor
Contributor

Sorry, just trying to help. Won't do it again.

0 Kudos