4

When all ports are open, you can use the Selenium ChromeDriver to collect the ports. However, as per company policy, only ports 53,443,80 are open. I can't run it when doing web collection using Selenium ChromeDriver. Checking the execution log, a certain random port is used. I found a way to manually configure that port. After manually setting the port to 4444, I added 4444 to the firewall port and it doesn't run on startup. What is the purpose of this port?

Is it possible to collect the web using the Selenium ChromeDriver by opening only ports 53, 443, 80 on the private network?

Please tell me a site where you can find a list of options related to Selenium and ChromeDriver execution, processes, structure, etc.

Below are my ChromeDriver options.

ChromeOptions options = new ChromeOptions();
            options.addArguments("--headless");
            options.setHeadless( _configInfo._driverHeadLess );
            options.addArguments("--disable-notifications");
            options.addArguments("--disable-push_messaging");
            options.addArguments("--disable-extensions");
            options.addArguments("--disable-cookies");
            options.addArguments("--disable-plugins");
            options.addArguments("--disable-mouselock");
            
            options.addArguments("--disable-media_stream");
            options.addArguments("--disable-media_stream_mic");
            options.addArguments("--disable-media_stream_camera");
            
            options.addArguments("--disable-ppapi_broker");
            options.addArguments("--disable-automatic_downloads");
            options.addArguments("--disable-midi_sysex");
            options.addArguments("--disable-metro_switch_to_desktop");
            options.addArguments("--disable-protected_media_identifier");
            options.addArguments("--disable-app_banner");
            options.addArguments("--disable-site_engagement");
            options.addArguments("--disable-durable_storage");
            options.addArguments("--whitelisted-ips");
            //options.addArguments("--single-process");
            //options.addArguments("--disable-dev-shm-usage");
            //options.addArguments("--no-sandbox");
ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(new 
                                   File("/lib/chromedriver")).usingPort(4444).build();
service.start();
WebDriver _driver = new RemoteWebDriver(service.getUrl(),options);
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
JeongWon_Lee
  • 43
  • 1
  • 7

1 Answers1

3

Chrome driver starts a server and exposes this server on the port specified.

So when you start the test, you talk to the server by talking to the exposed API (that's what APIs are for)

The driver server in turn talks to the browser through other protocols (used to be JSON wire protocol, now uses W3 protocol) And does what we requested

enter image description here

https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/remote/service/DriverService.Builder.html#usingPort(int)

https://www.selenium.dev/documentation/en/webdriver/understanding_the_components/

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
PDHide
  • 18,113
  • 2
  • 31
  • 46
  • Is the port communicating with the outside world? I checked the structure, but it is a function that works internally. I use it on the host PC, not the remote. Are there any port issues when WebDriver and ChromeDriver communicate with each other? You can open and use any port, but if you open only ports 80,443,53 you can't run it. – JeongWon_Lee Dec 09 '20 at 02:09
  • @JeongWon_Lee there is no external calls ,Starting ChromeDriver 87.0.4280.20 (c99e81631faa0b2a448e658c0dbd8311fb04ddbd-ref s/branch-heads/4280@{#355}) on port 4444 Only local connections are allowed. this is the message printed meaniong its runnign only on localhost IP binding not internet address 0.0.0.0 – PDHide Dec 09 '20 at 02:27
  • Yes, I think I understood But I have a strange problem. In iptables it won't run when all external ports except 80,443,53 are closed. Run locally. WebDriver/ChromeDriver runs locally inside. Why is there a problem closing the external port? – JeongWon_Lee Dec 09 '20 at 02:39
  • what OS windows or linux ? – PDHide Dec 09 '20 at 02:41
  • iptables -A INPUT -i lo -p tcp --dport $APP_PORT -j ACCEPT iptables -A INPUT -p tcp --dport $APP_PORT -j DROP – PDHide Dec 09 '20 at 02:44
  • you should allow localhost and then rejcet others else all inbound connections will be blocked – PDHide Dec 09 '20 at 02:45
  • https://unix.stackexchange.com/questions/419539/opening-all-ports-on-localhost-for-internal-communication/419549 – PDHide Dec 09 '20 at 02:46
  • Thanks for helping me solve the problem. I currently have to develop on a private network. Currently open ports (80,443,53) have 3 ports open. When I run chrome with selenium in this state, it won't run. However, if I turn off the firewall to open all ports, I can run chrome with selenium. It seems to be a port related issue, but I believe the structure of running chromeDriver with selenium doesn't need to open an external port due to internal communication. Selenium WebDriver and ChromeDriver run locally. Need to open the port? – JeongWon_Lee Dec 09 '20 at 04:58
  • you have to allow localhost connection to port and block all port for external inbound calls , now it seems like you have blocked all inbound calls (irrespecctive of external or internal) – PDHide Dec 09 '20 at 05:02
  • 80 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp spt:443 391 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp spt:53 420 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:4444 This is my iptables -nvL list. If you run selenium chromedriver in this state, it does not run. – JeongWon_Lee Dec 09 '20 at 05:06
  • Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 39 2776 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 if you run it in this state, selenium chromeDriver works normally without any problems. Do you know why? – JeongWon_Lee Dec 09 '20 at 05:08