info('Fetching proxies from ProxyScrape API...'); try { $response = Http::get('https://api.proxyscrape.com/v3/free-proxy-list/get?request=displayproxies&protocol=http&proxy_format=ipport&format=text&timeout=20000'); if (!$response->successful()) { throw new \Exception('Failed to fetch proxies: ' . $response->status()); } $proxyList = explode("\n", trim($response->body())); $this->info('Found ' . count($proxyList) . ' proxies'); $bar = $this->output->createProgressBar(count($proxyList)); $bar->start(); $saved = 0; $skipped = 0; foreach ($proxyList as $proxyString) { $proxyString = trim($proxyString); if (empty($proxyString)) continue; // Parse IP and Port from the proxy string list($ip, $port) = explode(':', $proxyString); $proxyUrl = "http://{$ip}:{$port}"; // Check if proxy already exists $exists = Proxy::where('proxy', $proxyUrl)->exists(); if (!$exists) { Proxy::create([ 'proxy' => $proxyUrl, 'protocol' => 'http', 'ip' => $ip, 'port' => (int) $port, 'https' => false, // Default to false since these are HTTP proxies 'anonymity' => 'unknown', // ProxyScrape doesn't provide anonymity info 'score' => 1, // Default score 'country' => null, // ProxyScrape doesn't provide geolocation 'city' => null, ]); $saved++; } else { $skipped++; } $bar->advance(); } $bar->finish(); $this->newLine(); $this->info("Proxies imported successfully!"); $this->info("New proxies saved: {$saved}"); $this->info("Existing proxies skipped: {$skipped}"); } catch (\Exception $e) { $this->error('Error: ' . $e->getMessage()); return 1; } return 0; } }