hhrzc
hhrzc

Reputation: 2051

BrowserMobProxy: How to determine IP for proxy server?

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.

Code where IP address used

  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);
    }
  }

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:

enter image description here

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:

enter image description here

So I totally confused:

  1. All works well before the docker image was restarted
  2. Old IP looks like 172.19.0.5 but the code fails with it now.
  3. I "found" new IP 172.17.0.2 and code work with it.
  4. I not sure I determined correct IP since all old IP was started with 172.19.0.{4,5,8}
  5. I have no connection with the new IP
  6. I do not know or I found the correct IP and why it suitable for code but not suitable for connection
  7. The project deploys with Jenkins docker image. Browsers start on the selenium grid

#Question:

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

Upvotes: 2

Views: 392

Answers (1)

Tch
Tch

Reputation: 1055

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

first you can try

netstat -an

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

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

then try

ip addr

which will give you a similar output as ifconfig

and last you can try with

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

which will give you the network interfaces of your docker

Upvotes: 2

Related Questions