Is there any way to detect, in general, if your code is executing on an Azure or Amazon virtual machine. I am not referring to some sort of web or worker role in particular, I mean given any executable, is there anything that resolves that machine to a cloud VM - for example under Azure there is no domain so i cannot simply rely on a domain name.
Available VM Sizes (SKUs) by Azure Region Product Page Now to check which services are available in your preferred Azure region, I recommend that you check out the Products available by region page on Azure.com. If you search for virtual machines, you will find a list of Azure VM sizes available per region.
To see all VMs on the local Hyper-V host, you should run the Get-VM cmdlet. On the PowerShell screen, you can see the list of available VMs, including their name, state, CPU usage, memory assigned, uptime, status, and version.
In the Windows Firewall with Advanced Security, you can enable the Echo Request – ICMPv4-In or Echo Request ICMPv6-In rules, depending on if you need IPv4 or IPv6. After doing both steps, you should be able to ping your Azure Virtual Machine (VM) using a public IP address.
If your guest has networking up then you can probe the instance metadata by accessing http://169.254.169.254
For example:
$ curl http://169.254.169.254/1.0/meta-data/instance-id
i-87dc2f76
However, hitting the network is fairly heavy-weight.
On AWS you can also check by looking at dmidecode:
$ /usr/sbin/dmidecode -s bios-version | tr "[:upper:]" "[:lower:]" | grep -q "amazon"
dmidecode is light-weight since it only hits the memory of the guest OS. However, as pointed out in previous answers it is dependent on Amazon continuing to include the word "amazon" in their version strings.
On Azure, you can detect the hypervisor details but this doesn't allow you to discriminate between Azure and HyperV. Depending on your scenario this might not be necessary.
To detect Azure/HyperV using dmidecode check the following strings:
$ /usr/sbin/dmidecode -s system-manufacturer | tr "[:upper:]" "[:lower:]" | grep -q "microsoft corporation"
$ /usr/sbin/dmidecode -s system-product-name | tr "[:upper:]" "[:lower:]" | grep -q "virtual machine"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With