Skip to content

Commit 9889575

Browse files
authored
Merge pull request #95 from clue-labs/wmic-multiple
Support parsing multiple DNS entries for same interface from WMIC
2 parents df893c0 + f5b8a57 commit 9889575

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/Config/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static function loadResolvConfBlocking($path = null)
115115
public static function loadWmicBlocking($command = null)
116116
{
117117
$contents = shell_exec($command === null ? 'wmic NICCONFIG get "DNSServerSearchOrder" /format:CSV' : $command);
118-
preg_match_all('/(?:{|,|")([\da-f.:]{4,})(?:}|,|")/i', $contents, $matches);
118+
preg_match_all('/(?<=[{;,"])([\da-f.:]{4,})(?=[};,"])/i', $contents, $matches);
119119

120120
$config = new self();
121121
$config->nameservers = $matches[1];

tests/Config/ConfigTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,22 @@ public function testLoadsSingleEntryForMultipleNicsFromWmicOutput()
152152
$this->assertEquals($expected, $config->nameservers);
153153
}
154154

155-
public function testLoadsMultipleEntriesForSingleNicFromWmicOutput()
155+
public function testLoadsMultipleEntriesForSingleNicWithSemicolonFromWmicOutput()
156+
{
157+
$contents = '
158+
Node,DNSServerSearchOrder
159+
ACE,
160+
ACE,{192.168.2.1;192.168.2.2}
161+
ACE,
162+
';
163+
$expected = array('192.168.2.1', '192.168.2.2');
164+
165+
$config = Config::loadWmicBlocking($this->echoCommand($contents));
166+
167+
$this->assertEquals($expected, $config->nameservers);
168+
}
169+
170+
public function testLoadsMultipleEntriesForSingleNicWithQuotesFromWmicOutput()
156171
{
157172
$contents = '
158173
Node,DNSServerSearchOrder

0 commit comments

Comments
 (0)