Created
June 9, 2016 02:05
-
-
Save PsyChip/20560c6634b24db582ef0daf0e556c45 to your computer and use it in GitHub Desktop.
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 | |
/* | |
* Wifi Configuration Library For Windows Vista/7/8/10 | |
* Uses operating system's built in utilities | |
* | |
* Armagan Corlu aka PsyChip | |
* March 2016 | |
* | |
*/ | |
class TwifiConfig { | |
var $adapters = []; | |
function __construct() { | |
$hede = shell_exec('ipconfig /all | findstr "\<Wireless LAN adapter Phy\>'); | |
$hede = str_replace('Wireless LAN adapter', 'Wireless LAN adapter' . chr(13) . chr(10), $hede); | |
$hede = str_replace('Description . . . . . . . . . . . : ', '', $hede); | |
$hede = str_replace('Wireless LAN adapter', '', $hede); | |
$hede = trim($hede); | |
$rawlines = explode(chr(13) . chr(10), $hede); | |
foreach ($rawlines as $line) { | |
$line = trim($line); | |
$this->adapters[trim($this->explodestr($line, 0, ':'))] = trim($this->explodestr($line, 1, ':')); | |
} | |
} | |
private function explodestr($string, $index, $char) { | |
$tmp = explode($char, $string); | |
return trim($tmp[$index]); | |
} | |
public function FindAdapter($device) { | |
# returns wifi device's friendly name which assigned by windows | |
foreach ($this->adapters as $k => $v) { | |
if ($v === $device) { | |
return $k; | |
} | |
} | |
} | |
public function SetDHCP($device) { | |
# activates DHCP on provided device name | |
$fn = $this->FindAdapter($device); | |
if ($fn !== "") { | |
shell_exec('netsh interface ip set address "' . $fn . '" dhcp'); | |
return true; | |
} | |
return false; | |
} | |
public function SetStatic($device, $params) { | |
# configures TCP parameters of the specified adapter | |
# parameter array must contain keys: ip,mask,gateway,dns1,dns2 | |
$fn = $this->FindAdapter($device); | |
if ($fn !== "") { | |
shell_exec('netsh interface ip set address name="' . $fn . '" static ' . $params['ip'] . ' ' . $params['mask'] . ' ' . $params['gateway'] . ' 1'); | |
shell_exec('netsh interface ip set dns name="' . $fn . '" source=static addr=' . $params['dns1'] . ' register=primary'); | |
shell_exec('netsh interface ip add dns name="' . $fn . '" addr=' . $params['dns2'] . ' index=2'); | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment