Skip to content

Instantly share code, notes, and snippets.

@sytone
Last active December 27, 2015 19:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sytone/2495a69c352623b6c9bd to your computer and use it in GitHub Desktop.
Returns the DHCP list for a ASUS router.
$username = "admin"
# read-host -assecurestring | convertfrom-securestring | out-file .\securestring.txt
$password = cat .\securestring.txt | convertto-securestring
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
$page = Invoke-WebRequest -Uri "http://192.168.0.1/Main_DHCPStatus_Content.asp" -Credential $cred
$dhcpList = $page.AllElements | where tagName -eq "textarea" | Select -First 1 -ExpandProperty innerText
$rows = @()
$dhcpList.split("`n")[(1..($dhcpList.split("`n").Length-1))] | % {
$row = $_.split(" ",[StringSplitOptions]'RemoveEmptyEntries')
[PSCustomObject]@{
IP = $row[1];
MACAddress = $row[2];
Expires = [int]($row[3].split(":")[0])*60*60 + [int]($row[3].split(":")[1])*60 + [int]($row[3].split(":")[2]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment