wonder if I can get another pair of eyes on this.
Use case; grabbing DNS records from zone file in order to run shell_exec to import them into another platform.
I am trying to grab all types of DNS records from a zone file, A record, CNAME, TXT, MX etc. I am doing well so far in that I have managed to do CNAME, TXT and MX records.
I am stuck on the A record. Unfortunately, as I am searching each line of the file for A, this is causing CNAME and the SOA to be returned also. Here's what I have:
// Looking for:
$search_a = 'A';
// Read from file
$lines = file("$domain.");
// Check if the line contains A
foreach($lines as $a) {
if(strpos($a, $search_a) !== false) {
$a_array = "$a";
$a_record_output = preg_split('/(.'.$domain.'.|\s)/', $a_array, -1, PREG_SPLIT_NO_EMPTY);
print_r($a_record_output);
}
}
This returns:
Array
(
[0] => domain.io.
[1] => SOA
[2] => ns1.domain.io.
[3] => stuff.
[4] => (64719
[5] => 14400
[6] => 7200
[7] => 2419200
[8] => 3600)
)
Array
(
[0] => domain.io.
[1] => A
[2] => 8.8.8.8
)
Array
(
[0] => autodiscover
[1] => CNAME
[2] => autodiscover.outlook.com.
)
Obviously it is working, however, I need to exclude the SOA and CNAME record as I am only searching for A records.
I need to completely ignore the CNAME and SOA arrays and only return ones which contain just A. Here's an extract from the zone file
domain.io. A 8.8.8.8
www CNAME domain.io
Is there a way of doing this?