BrowserMobProxy:如何确定代理服务器的IP? [英] BrowserMobProxy: How to determine IP for proxy server?

查看:46
本文介绍了BrowserMobProxy:如何确定代理服务器的IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中实现了 BrowserMobProxy .此逻辑使用IP地址进行代理连接和测试UI Web服务(用于保存请求/响应统计信息的代理).之前一切正常,但是我们重新启动了docker并更改了代理的IP地址.现在,我需要为代理找到一个新的IP地址.

I have BrowserMobProxy realization in the project. This logic uses the IP address for Proxy connection and test UI web-service (Proxy used for request/response statistic saving). All worked fine before, but we restart docker and the IP address for the proxy was changed. Now I need to found a new IP address for the proxy.

使用IP地址的代码

  public static void startProxyServer(String address) {//address = "172.17.0.2"
    if (browserMobProxy.isStarted()) {
      browserMobProxy.stop();
    }
    try {
      browserMobProxy.start(9090, Inet4Address.getByName(address)); // {1}
      useExclusivePort = browserMobProxy.getPort();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

泊坞窗重新启动后,项目开始在行 {1} 上失败.我开始在服务器上搜索新IP.不幸的是,我无法使用docker镜像中的 ifconfig 命令,因为该命令未安装在该镜像中.因此,我通过以下方式确定了服务器的地址:

After docker was restarting the project began fails on the line {1}. I started the search for new IP on the server. Unfortunately, I can't use ifconfig command from the docker image since this command does not install there. So I determined the address from the server in the following way:

使用IP 172.17.0.2后,代码运行良好,希望我能解决此问题,但事实证明,我失去了与此代理的连接-在UI上,我得到了以下结果:

After I use IP 172.17.0.2 the code works well and I hoped I resolved this issue, but as it turned out I lost connection with this proxy - on the UI I got the following result:

所以我完全困惑:

  1. 在重新启动docker映像之前一切正常
  2. 旧IP看起来像172.19.0.5,但是现在代码失败了.
  3. 我找到"了新的IP 172.17.0.2并使用它的代码.
  4. 我不确定我确定正确的IP,因为所有旧IP都是从172.19.0开始的.{4,5,8}
  5. 我与新IP没有连接
  6. 我不知道,或者我找到了正确的IP,为什么它适合代码但不适合连接
  7. 该项目使用Jenkins docker映像进行部署.浏览器从硒网格开始

#问题:

我如何找到可以用于代理连接的正确IP?

How do I need to found the correct IP that I can use for a proxy connection?

推荐答案

还有其他一些命令,您可以使用它们找到服务器在哪个IP上运行.检查您是否有权访问以下任何一项

there are other commands with which you can find which ip your server is running on. check if you have access to any of the following

首先您可以尝试

netstat -an

这将为您提供服务器正在侦听的所有IP,以及哪些端口以及端口上与之连接的IP

which will give you all IPs your server is listening to along with what ports, and what IPs are connected on it along with the ports

如果这不起作用,请尝试此 https://dev.to/trexinc/netstat-without-netstat-内部容器9ak

if this doesn't work try this https://dev.to/trexinc/netstat-without-netstat-inside-containers-9ak

然后尝试

ip addr

这将为您提供与ifconfig类似的输出

which will give you a similar output as ifconfig

最后,您可以尝试

docker inspect -f '{{ .NetworkSettings.IPAddress }}' containerID

这将为您提供码头工人的网络接口

which will give you the network interfaces of your docker

这篇关于BrowserMobProxy:如何确定代理服务器的IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆