/**
  * @param GoogleUrlInterface $googleUrl
  * @param BrowserInterface|null $browser
  * @return GoogleSerp
  * @throws Exception
  * @throws PageNotFoundException
  * @throws InvalidResponseException
  * @throws PageNotFoundException
  * @throws GoogleCaptchaException
  */
 public function query(GoogleUrlInterface $googleUrl, BrowserInterface $browser = null)
 {
     if ($googleUrl->getResultType() !== GoogleUrl::RESULT_TYPE_ALL) {
         throw new Exception('The requested url is not valid for the google client.' . 'Google client only supports general searches. See GoogleUrl::setResultType() for more infos.');
     }
     if (null === $browser) {
         $browser = $this->defaultBrowser;
     }
     if (!$browser) {
         throw new Exception('No browser given for query and no default browser was found');
     }
     $response = $browser->navigateToUrl($googleUrl);
     $statusCode = $response->getHttpResponseStatus();
     $effectiveUrl = GoogleUrlArchive::fromString($response->getEffectiveUrl()->__toString());
     if (200 == $statusCode) {
         return new GoogleSerp($response->getPageContent(), $effectiveUrl);
     } else {
         if (404 == $statusCode) {
             throw new PageNotFoundException($response);
         } else {
             $errorDom = new GoogleError($response->getPageContent(), $effectiveUrl);
             if ($errorDom->isCaptcha()) {
                 throw new GoogleCaptchaException(new GoogleCaptcha($errorDom));
             } else {
                 $failedUrl = $response->getInitialUrl();
                 throw new InvalidResponseException($response, "The http response from {$failedUrl} has an invalid status code: '{$statusCode}'");
             }
         }
     }
 }
 public function getDetectedIp()
 {
     $ipV4 = '(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})';
     $ipV6 = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))';
     $regexp = "/({$ipV4}|{$ipV6})/";
     $hasMatch = preg_match($regexp, $this->googleError->getDom()->C14N(), $match);
     if ($hasMatch) {
         return $match[1];
     } else {
         return null;
     }
 }