mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-22 16:03:22 +01:00
Added list-fritzbox-devices.ps1
This commit is contained in:
parent
4f2d93d09a
commit
718268a60f
@ -23,6 +23,7 @@ list-empty-dirs.ps1, lists empty subfolders in a directory tree
|
||||
list-files.ps1, lists all files in the given folder and also in every subfolder
|
||||
list-formatted.ps1, lists the current working directory formatted in columns
|
||||
list-fritzbox-calls.ps1, lists the FRITZ!Box calls
|
||||
list-fritzbox-devices.ps1, lists the FRITZ!Box devices
|
||||
list-installed-software.ps1, lists the installed software
|
||||
list-logbook.ps1, lists the content of the logbook
|
||||
list-unused-files.ps1, lists unused files in a directory tree
|
||||
|
|
@ -32,6 +32,7 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol
|
||||
* [list-files.ps1](Scripts/list-files.ps1) - lists all files in the given folder and also in every subfolder
|
||||
* [list-formatted.ps1](Scripts/list-formatted.ps1) - lists the current working directory formatted in columns
|
||||
* [list-fritzbox-calls.ps1](Scripts/list-fritzbox-calls.ps1) - lists the FRITZ!Box calls
|
||||
* [list-fritzbox-devices.ps1](Scripts/list-fritzbox-devices.ps1) - lists the FRITZ!Box devices
|
||||
* [list-logbook.ps1](Scripts/list-logbook.ps1) - lists the content of the logbook
|
||||
* [list-unused-files.ps1](Scripts/list-unused-files.ps1) - lists unused files in a directory tree
|
||||
* [list-cmdlets.ps1](Scripts/list-cmdlets.ps1) - lists the PowerShell cmdlets
|
||||
|
119
Scripts/list-fritzbox-devices.ps1
Normal file
119
Scripts/list-fritzbox-devices.ps1
Normal file
@ -0,0 +1,119 @@
|
||||
#!/snap/bin/powershell
|
||||
<#
|
||||
.SYNTAX ./list-fritzbox-calls.ps1 [<username>] [<password>]
|
||||
.DESCRIPTION lists the phone calls of the FRITZ!Box device
|
||||
.LINK https://github.com/fleschutz/PowerShell
|
||||
.NOTES Author: Markus Fleschutz / License: CC0
|
||||
#>
|
||||
|
||||
param (
|
||||
[String]$hostURL = "https://fritz.box:49443", # IP of fritz-box
|
||||
[string]$SOAPAction="urn:dslforum-org:service:Hosts:1#X_AVM-DE_GetHostListPath",
|
||||
[Parameter(Mandatory=$true)][string]$Username = "", # username for Fritz!Box
|
||||
[Parameter(Mandatory=$true)][string]$FBKennwort="", # password for Fritz!Box
|
||||
[switch]$onlyactive, #limit to active hosts
|
||||
[switch]$prtg, #return PRTX XML wit num of active and passice hosts
|
||||
[switch]$prtgdetail #return full xml with a channel per mac, be careful with many hosts
|
||||
)
|
||||
|
||||
write-host "get-fritzmactable: Start"
|
||||
|
||||
if ($FBKennwort -eq "") {
|
||||
Write-Host "Password required"
|
||||
Write-Error "Password required"
|
||||
exit
|
||||
}
|
||||
|
||||
|
||||
Write-host " Prepare SOAP-Request"
|
||||
[string]$SOAPrequest = @"
|
||||
<?xml version="1.0"?>
|
||||
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
||||
<s:Body>
|
||||
<u:X_AVM-DE_GetHostListPath xmlns:u="urn:dslforum-org:service:Hosts:1" />
|
||||
</s:Body>
|
||||
</s:Envelope>
|
||||
"@
|
||||
|
||||
Write-host " Prepare Credentials"
|
||||
$secure_pwd = $FBKennwort | ConvertTo-SecureString -AsPlainText -Force
|
||||
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $secure_pwd
|
||||
|
||||
Write-Host " Request DownloadURL via SOAP"
|
||||
$ReturnXml = Invoke-RestMethod `
|
||||
-Method POST `
|
||||
-Headers @{'SOAPAction'=($soapaction)} `
|
||||
-Uri ($hostURL+"/upnp/control/hosts") `
|
||||
-Credential $creds `
|
||||
-ContentType 'text/xml' `
|
||||
-Body $SOAPrequest
|
||||
|
||||
Write-host " Download MAC-List from ($hostURL($($ReturnXml.Envelope.Body.'X_AVM-DE_GetHostListPathResponse'.'NewX_AVM-DE_HostListPath')))"
|
||||
$devicehostlist = invoke-restmethod `
|
||||
-Uri ($hostURL+($ReturnXml.Envelope.Body.'X_AVM-DE_GetHostListPathResponse'.'NewX_AVM-DE_HostListPath'))
|
||||
# convert System.Xml.XmlLinkedNode to standard Object
|
||||
$mactable = $devicehostlist.List.Item.GetEnumerator() | ConvertTo-Csv | ConvertFrom-Csv
|
||||
Write-host "Total Entries: $($mactable.count)"
|
||||
|
||||
Write-host " Loading List Done"
|
||||
if ($prtgdetail) {
|
||||
"<?xml version=""1.0"" encoding=""UTF-8"" ?>
|
||||
<prtg>
|
||||
<result>
|
||||
<channel>Active Hosts</channel>
|
||||
<value>$(($mactable | where-object {$_.active -eq 1}).count)</value>
|
||||
<float>0</float>
|
||||
</result>
|
||||
<result>
|
||||
<channel>Passive Hosts</channel>
|
||||
<value>$(($mactable | where-object {$_.active -eq 0}).count)</value>
|
||||
<float>0</float>
|
||||
</result>
|
||||
<result>
|
||||
<channel>Guest Hosts</channel>
|
||||
<value>$(($mactable | where-object {$_."X_AVM-DE_Guest" -eq 1}).count)</value>
|
||||
<float>0</float>
|
||||
</result>"
|
||||
foreach ($mac in $mactable) {
|
||||
"<result>
|
||||
<channel>$($mac.MACAddress)</channel>
|
||||
<value>$($mac.active)</value>
|
||||
<float>0</float>
|
||||
</result>"
|
||||
}
|
||||
|
||||
"<text>Anzahl der Eintraege in der FB MacTabelle</text>
|
||||
</prtg>"
|
||||
}
|
||||
elseif ($prtg) {
|
||||
"<?xml version=""1.0"" encoding=""UTF-8"" ?>
|
||||
<prtg>
|
||||
<result>
|
||||
<channel>Active Hosts</channel>
|
||||
<value>$(($mactable | where-object {$_.active -eq 1}).count)</value>
|
||||
<float>0</float>
|
||||
</result>
|
||||
<result>
|
||||
<channel>Passive Hosts</channel>
|
||||
<value>$(($mactable | where-object {$_.active -eq 0}).count)</value>
|
||||
<float>0</float>
|
||||
</result>
|
||||
<result>
|
||||
<channel>Guest Hosts</channel>
|
||||
<value>$(($mactable | where-object {$_."X_AVM-DE_Guest" -eq 1}).count)</value>
|
||||
<float>0</float>
|
||||
</result>
|
||||
<text>Anzahl der Eintraege in der FB MacTabelle</text>
|
||||
</prtg>"
|
||||
|
||||
}
|
||||
else {
|
||||
if ($onlyactive) {
|
||||
Write-Host "Export active entries"
|
||||
$mactable | where-object {$_.active -eq 1}
|
||||
}
|
||||
else {
|
||||
Write-Host "Export all entries"
|
||||
$mactable
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user