获取Heroku测功机的IP [英] Get IP of Heroku dynos
问题描述
我有一个Heroku应用,对外部服务进行一些API调用.存在一些问题,服务希望知道哪些IP正在拨打电话.
I have a Heroku app making some API calls to an external service. There are some issues and the service wants to know what IPs are making the calls.
计算机上不存在许多基本工具,例如ifconfig
,traceroute
,netstat
等.看起来他们正在运行非常准系统的Ubuntu 14.04.5.
A lot of the basic tools like ifconfig
, traceroute
, netstat
, etc don't exist on the machines. Looks like they are running a very barebones version of Ubuntu 14.04.5.
我能够使用heroku ps:exec -a <myapp>
SSH进入我的应用程序并使用ip addr
,但是存在一些问题:
I was able to use heroku ps:exec -a <myapp>
to SSH into my app and use ip addr
but there are some problems:
1)看来,这仅允许我SSH进入web.1 dyno(并且我正在通过rest.1,rest.2等进行API调用) 2)这些呼叫经过Heroku一侧的路由器.
1) It appears that this only allows me to SSH into the web.1 dyno (and I am making my API calls through rest.1, rest.2, etc.) 2) These calls go through a router on Heroku's side.
如何获取所有dyno实例和/或路由器的IP?
How can I get the IPs of all dyno instances and/or the router?
推荐答案
使用heroku ps -a <app>
命令获取测功机列表.
Get the list of dynos with the heroku ps -a <app>
command.
实际上,您可以使用heroku ps:exec -a <app> -d <dyno_instance> --ssh
ssh进入单个dyno实例.
You actually can ssh into individual dyno instances with heroku ps:exec -a <app> -d <dyno_instance> --ssh
.
使用ip
命令获取单独的dyno IP,例如ip addr | grep "global eth0" | awk '{ print $2 }'
.
Get the individual dyno IP with the ip
command e.g. ip addr | grep "global eth0" | awk '{ print $2 }'
.
使用curl 'https://api.ipify.org'
获取路由器IP. http://httpbin.org/ip 也很好.
Get the router IP with curl 'https://api.ipify.org'
. http://httpbin.org/ip is also good.
您可以使用expect
通过运行Heroku SSH命令以编程方式从每个dyno检索IP,等待提示,运行IP命令,注销,然后为每个dyno实例重复.
You could use expect
to programmatically retrieve the IPs from every dyno by running the Heroku SSH command, waiting for the prompt, running the IP command(s), logging out, then repeating for each dyno instance.
这篇关于获取Heroku测功机的IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!