ldanielw1
ldanielw1

Reputation: 351

Microsoft Azure: Find public-ip from command line of the created instance

I want to be able to run a script on each deployed VM in Azure that depends on the VM's public IP address.

Is there any way, from the shell, that I could curl some URL, or run the command line interface, or do anything, really, to find this information?

Upvotes: 3

Views: 4465

Answers (2)

Michael B
Michael B

Reputation: 12228

Taken from here

curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'  

That will get you your public, outgoing IP address.

I have previously configured a small API App that has credentials to Azure Subscriptions that searches through the subscriptions for the IP Address and returns a JSON document with some pertinent configuration. (and complained a little that AWS gives you this stuff for free!)

Upvotes: 10

Sam Texas
Sam Texas

Reputation: 1275

I keep shortcuts like this in my gists, which is pasted here:

azure vm show <RG_GROUP> <VM_NAME> |grep "Public IP address" | awk -F ":" '{print $3}'

This should give you the public IP address attached to the machine.

Note: I have not tested it with multiple public IPs attached to a single machine. This only covers the basic use case.

Upvotes: 1

Related Questions