Created
February 25, 2021 07:43
-
-
Save thistehneisen/9f1f09b6b852f4ff7c4741795c0682b6 to your computer and use it in GitHub Desktop.
Simple PHP script to verify HTTP response codes from domain list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$addresses = file('addresses.txt', FILE_IGNORE_NEW_LINES); | |
$responding = []; | |
foreach ($addresses as $address) { | |
if ($url = parse_url($address)) { | |
if (!isset($url['scheme'])) { | |
$address = 'http://' . $address; | |
} | |
} | |
if (!filter_var($address, FILTER_VALIDATE_URL)) { | |
print($address . ' doesn\'t qualify as an valid URL').PHP_EOL; | |
continue; | |
} | |
$ch = curl_init($address); | |
curl_setopt($ch, CURLOPT_HEADER, true); | |
curl_setopt($ch, CURLOPT_NOBODY, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); | |
curl_setopt($ch, CURLOPT_TIMEOUT,4); | |
$output = curl_exec($ch); | |
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
if ($httpCode !== 0) { | |
print($address . ' has HTTP code: ' . $httpCode) . PHP_EOL; | |
if (in_array($httpCode, [301, 302])) { | |
$address = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); | |
print('=> ' . $address).PHP_EOL; | |
} | |
$responding[$httpCode][] = $address; | |
} | |
file_put_contents('result.txt', print_r($responding, true)); | |
curl_close($ch); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment