Revision 0057e62d
Added by Chris Buechler almost 10 years ago
etc/inc/pfsense-utils.inc | ||
---|---|---|
127 | 127 |
|
128 | 128 |
/****f* pfsense-utils/get_dns_servers |
129 | 129 |
* NAME |
130 |
* get_dns_servres - get system dns servers
|
|
130 |
* get_dns_servers - get system dns servers
|
|
131 | 131 |
* INPUTS |
132 |
* $dns_servers - an array of the dns servers
|
|
132 |
* none
|
|
133 | 133 |
* RESULT |
134 |
* null
|
|
134 |
* $dns_servers - an array of the dns servers
|
|
135 | 135 |
******/ |
136 | 136 |
function get_dns_servers() { |
137 | 137 |
$dns_servers = array(); |
138 |
$dns_s = file("/etc/resolv.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
139 |
foreach ($dns_s as $dns) { |
|
140 |
$matches = ""; |
|
141 |
if (preg_match("/nameserver (.*)/", $dns, $matches)) { |
|
142 |
$dns_servers[] = $matches[1]; |
|
143 |
} |
|
138 |
if (file_exists("/etc/resolv.conf")) { |
|
139 |
$dns_s = file("/etc/resolv.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
140 |
} |
|
141 |
if (is_array($dns_s)) { |
|
142 |
foreach ($dns_s as $dns) { |
|
143 |
$matches = ""; |
|
144 |
if (preg_match("/nameserver (.*)/", $dns, $matches)) { |
|
145 |
$dns_servers[] = $matches[1]; |
|
146 |
} |
|
147 |
} |
|
144 | 148 |
} |
145 | 149 |
return array_unique($dns_servers); |
146 | 150 |
} |
Also available in: Unified diff
only read file if it exists, and only foreach if an array.