如何检测Azure / Amazon VM

时间:2012-07-19 23:49:20

标签: azure amazon virtual-machine

通常,是否有任何方法可以检测您的代码是在Azure或Amazon虚拟机上执行的。我并不是指某种特定的Web或工作者角色,我的意思是给出任何可执行文件,是否有任何东西可以将该机器解析为云VM - 例如在Azure下没有域,所以我不能简单地依赖域名

5 个答案:

答案 0 :(得分:4)

AWS

如果您的访客已联网,则可以通过访问http://169.254.169.254

来探测实例元数据

例如:

$ curl http://169.254.169.254/1.0/meta-data/instance-id
i-87dc2f76

然而,击中网络相当重。

在AWS上,您还可以查看dmidecode:

进行检查
$ /usr/sbin/dmidecode -s bios-version | tr "[:upper:]" "[:lower:]" | grep -q "amazon"

dmidecode重量轻,因为它只能访问来宾操作系统的内存。但是,正如之前的回答所指出的,它依赖于亚马逊继续在其版本字符串中包含“amazon”一词。

天青

在Azure上,您可以检测管理程序详细信息,但这不允许您区分Azure和HyperV。根据您的情况,这可能没有必要。

要使用dmidecode检测Azure / HyperV,请检查以下字符串:

$ /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"

答案 1 :(得分:3)

您可以查看机器的IP地址,并确定它是否在特定云的IP地址块中。

对于Azure,每个子区域的已发布的ip地址范围列表是xml文件:

http://download.microsoft.com/download/E/F/C/EFC5E4D8-E4EA-4EFE-9356-D8AEEBC85F50/Azure_IP_Ranges.xml

亚马逊会在添加新范围时发布博客条目。他们目前是:

美国东部(弗吉尼亚北部):

  • 72.44.32.0/19(72.44.32.0 - 72.44.63.255)
  • 67.202.0.0/18(67.202.0.0 - 67.202.63.255)
  • 75.101.128.0/17(75.101.128.0 - 75.101.255.255)
  • 174.129.0.0/16(174.129.0.0 - 174.129.255.255)
  • 204.236.192.0/18(204.236.192.0 - 204.236.255.255)
  • 184.73.0.0/16(184.73.0.0 - 184.73.255.255)
  • 184.72.128.0/17(184.72.128.0 - 184.72.255.255)
  • 184.72.64.0/18(184.72.64.0 - 184.72.127.255)
  • 50.16.0.0/15(50.16.0.0 - 50.17.255.255)
  • 50.19.0.0/16(50.19.0.0 - 50.19.255.255)
  • 107.20.0.0/14(107.20.0.0 - 107.23.255.255)
  • 23.20.0.0/14(23.20.0.0 - 23.23.255.255)
  • 54.242.0.0/15(54.242.0.0 - 54.243.255.255)
  • 54.234.0.0/15(54.234.0.0 - 54.235.255.255)新
  • 54.236.0.0/15(54.236.0.0 - 54.237.255.255)新

美国西部(俄勒冈州):

  • 50.112.0.0/16(50.112.0.0 - 50.112.255.255)
  • 54.245.0.0/16(54.245.0.0 - 54.245.255.255)

美国西部(加利福尼亚州北部):

  • 204.236.128.0/18(204.236.128.0 - 204.236.191.255)
  • 184.72.0.0/18(184.72.0.0 - 184.72.63.255)
  • 50.18.0.0/16(50.18.0.0 - 50.18.255.255)
  • 184.169.128.0/17(184.169.128.0 - 184.169.255.255)
  • 54.241.0.0/16(54.241.0.0 - 54.241.255.255)

欧盟(爱尔兰):

  • 79.125.0.0/17(79.125.0.0 - 79.125.127.255)
  • 46.51.128.0/18(46.51.128.0 - 46.51.191.255)
  • 46.51.192.0/20(46.51.192.0 - 46.51.207.255)
  • 46.137.0.0/17(46.137.0.0 - 46.137.127.255)
  • 46.137.128.0/18(46.137.128.0 - 46.137.191.255)
  • 176.34.128.0/17(176.34.128.0 - 176.34.255.255)
  • 176.34.64.0/18(176.34.64.0 - 176.34.127.255)
  • 54.247.0.0/16(54.247.0.0 - 54.247.255.255)
  • 54.246.0.0/16(54.246.0.0 - 54.246.255.255)新

亚太地区(新加坡)

  • 175.41.128.0/18(175.41.128.0 - 175.41.191.255)
  • 122.248.192.0/18(122.248.192.0 - 122.248.255.255)
  • 46.137.192.0/18(46.137.192.0 - 46.137.255.255)
  • 46.51.216.0/21(46.51.216.0 - 46.51.223.255)
  • 54.251.0.0/16(54.251.0.0 - 54.251.255.255)

亚太(东京)

  • 175.41.192.0/18(175.41.192.0 - 175.41.255.255)
  • 46.51.224.0/19(46.51.224.0 - 46.51.255.255)
  • 176.32.64.0/19(176.32.64.0 - 176.32.95.255)
  • 103.4.8.0/21(103.4.8.0 - 103.4.15.255)
  • 176.34.0.0/18(176.34.0.0 - 176.34.63.255)
  • 54.248.0.0/15(54.248.0.0 - 54.249.255.255)

南美洲(圣保罗)

  • 177.71.128.0/17(177.71.128.0 - 177.71.255.255)
  • 54.232.0.0/16(54.232.0.0 - 54.232.255.255)新

答案 2 :(得分:1)

这是检查机器实例是否在亚马逊中的内部方法:

dmidecode | grep Version
version: 4.2.amazon     <--- This is what you would want to key on

只有亚马逊在VM的虚拟BIOS设置中保留其签名时,这才会有效。我没有使用Azure,但我相信您也可以使用dmidecode来推断信息。我已经使用VMware和VirtualBox完成了它。

答案 3 :(得分:0)

@ Dan的回答不再适用于Azure,请使用以下网址获取更好的列表

http://msdn.microsoft.com/en-us/library/windowsazure/dn175718.aspx

如果这个网址已经消失,请点击今天(2013年8月12日)

Europe West
65.52.128.0/19
213.199.128.0/20
168.63.0.0/19
168.63.96.0/19
137.116.192.0/19
137.117.128.0/17
168.61.56.0/21

Europe North
65.52.64.0/20
65.52.224.0/19
168.63.92.0/22
168.63.32.0/19
94.245.88.0/21
94.245.104.0/21
168.63.64.0/20
168.63.80.0/20
168.61.96.0/19
137.116.224.0/20

US East
168.62.32.0/19
157.56.176.0/21
168.62.160.0/19
168.61.32.0/20
168.61.48.0/21
137.117.64.0/18
137.135.64.0/18
138.91.96.0/19
137.116.112.0/20

US West
168.62.192.0/20
168.62.208.0/21
168.61.0.0/20
168.61.64.0/20
137.117.0.0/19
137.135.0.0/18
137.116.184.0/21
138.91.64.0/19
65.52.112.0/20
168.63.89.0/24
157.56.160.0/21
168.62.0.0/19

US North Central
65.52.0.0/19
65.52.0.0/20
65.52.16.0/20
65.52.192.0/19
65.52.48.0/20
157.55.24.0/21
157.55.64.0/20
157.55.160.0/20
157.55.136.0/21
157.55.208.0/20
157.56.8.0/21
157.55.252.0/22
168.62.96.0/19
157.55.248.0/22
168.62.224.0/19

US South Central
157.55.176.10/22
157.55.183.223/27
157.55.184.10/22
157.55.191.223/27
157.55.192.10/24
157.55.193.223/27
157.55.194.10/24
157.55.195.223/27
157.55.196.10/23
157.55.200.10/23
157.55.80.10/23
157.55.83.223/27
157.55.84.10/23
157.55.87.223/27
65.52.32.10/22
65.52.39.224/28
70.37.160.10/22
70.37.167.224/28
70.37.118.0/24
70.37.119.138/28
70.37.119.170/28
70.37.48.10/22
70.37.55.224/28
70.37.56.10/22
70.37.63.224/28
70.37.116.0/24

SE Asia
111.221.96.0/20
168.63.160.0/19
111.221.80.0/20
168.63.224.0/19
137.116.128.0/19

East Asia
65.52.160.0/19
111.221.78.0/23
168.63.128.0/19
168.63.192.0/19
137.116.160.0/20

答案 4 :(得分:0)

您也可以为 Azure VM 使用元数据终结点:

Invoke-RestMethod -Headers @{"Metadata"="true"} -Method GET -Proxy $Null -Uri "http://169.254.169.254/metadata/instance?api-version=2021-02-01" | ConvertTo-Json -Depth 64

参考: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service?tabs=windows