有此VM元数据东西都AWS和Azure的:
https://azure.microsoft.com/en-us/blog/what-just-happened-to-my-vm-in-vm-metadata-service/
,但目前有由源返回的信息非常少:
UbuntuInJapan:~$ curl -s http://169.254.169.254/metadata/latest/InstanceInfo
{"ID":"_UbuntuInJapan","UD":"0","FD":"0"}
...只是升级和故障域,这对你的努力毫无用处。
对于公网IP,这是我平时做:
#!/bin/bash
PUBLIC_IP=$(curl -s http://checkip.amazonaws.com || printf "0.0.0.0")
# Then you either get the public IP address in the variable or you get 0.0.0.0
# which means you could not make the call to Amazon or Amazon is under DDoS.
# amirite?
# Uncomment to echo (AKA debug mode)
echo $PUBLIC_IP
你可以链接多个什么是我的IP?服务来增加您的SLA。 即:
# First one that works wins.
# You can improve this by regex checking the output.
#
# Something like:
#
# if [[ $PUBLIC_IP =~ [[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\/ ]]
# then echo 'Good. Valid IPv4. Continue.'
# else echo 'Bad. Stop.'
# fi
UbuntuInJapan:~$ curl -s http://checkip.amazonaws.FAILS || curl -s http://canihazip.com/s
13.78.92.21
有些服务将返回IPv6的,如果你谈论的IPv6给他们,请确保您的地址族明确地传递给curl
:
$ curl -4 http://l2.io/ip
13.78.92.21
$ curl -6 http://l2.io/ip
2a02:2f0b:4xxx:fxxx:4xxx:xxxx:xxxx:1072
你需要击出了一些外面的网址告诉你连接来自的IP是什么,例如,击中“什么是我的IP”网站。也许天青有一个webservice,你可以打到告诉你,而不需要“走出去”。 –
感谢您的建议!我在Azure的文档中花费了最后一两个小时,似乎并没有像这样的东西。基于你的建议,我能够找到“http://www.linuxtrainingacademy.com/determine-public-ip-address-command-line-curl/”,然后运行“curl ifconfig.me”能够让我我的公共IP。谢谢! –