I am stuck with this error while trying to read a file which holds IP addresses separated by a new line. What I want to do, is to read my file that holds bunch of IP's and check does they have proper record. This is my code:
$file = "test.sh";
if (is_file($file) && is_readable($file)) {
$get_file_data = file_get_contents($file);
$turn_to_array = explode("\n", $get_file_data);
foreach ($turn_to_array as $key => $value) {
if (filter_var($value, FILTER_VALIDATE_IP)) {
echo gethostbyaddr(trim($value));
} else {
echo "IP invalid";
}
}
}
My test.sh file looks like following:
EDIT : example IP's
180.1.1.1
181.1.1.2
Do I need to add some specific tests to parse a file or there is some other issue?
The error caused by the very unique method used:
Warning: gethostbyaddr(): Address is not a valid IPv4 or IPv6 PHP
Solved.
My code was working, I wasn't getting rdns record properly, since it didn't exist for those IP's. I've checked it with host 185.1.1.1 and it returned actual IP not domain. Then checked IP's for whom I was sure that they have PTR records, and it woked. But I am not sure exactly how error was fixed actually.