diff --git a/Data/scripts.csv b/Data/scripts.csv index 92e0e858..911ed68c 100644 --- a/Data/scripts.csv +++ b/Data/scripts.csv @@ -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 diff --git a/README.md b/README.md index 8714b429..63acfa55 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Scripts/list-fritzbox-devices.ps1 b/Scripts/list-fritzbox-devices.ps1 new file mode 100644 index 00000000..7fbd10b9 --- /dev/null +++ b/Scripts/list-fritzbox-devices.ps1 @@ -0,0 +1,119 @@ +#!/snap/bin/powershell +<# +.SYNTAX ./list-fritzbox-calls.ps1 [] [] +.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 = @" + + + + + + +"@ + +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) { + " + + + Active Hosts + $(($mactable | where-object {$_.active -eq 1}).count) + 0 + + + Passive Hosts + $(($mactable | where-object {$_.active -eq 0}).count) + 0 + + + Guest Hosts + $(($mactable | where-object {$_."X_AVM-DE_Guest" -eq 1}).count) + 0 + " + foreach ($mac in $mactable) { + " + $($mac.MACAddress) + $($mac.active) + 0 + " + } + + "Anzahl der Eintraege in der FB MacTabelle + " +} +elseif ($prtg) { + " + + + Active Hosts + $(($mactable | where-object {$_.active -eq 1}).count) + 0 + + + Passive Hosts + $(($mactable | where-object {$_.active -eq 0}).count) + 0 + + + Guest Hosts + $(($mactable | where-object {$_."X_AVM-DE_Guest" -eq 1}).count) + 0 + + Anzahl der Eintraege in der FB MacTabelle + " + +} +else { + if ($onlyactive) { + Write-Host "Export active entries" + $mactable | where-object {$_.active -eq 1} + } + else { + Write-Host "Export all entries" + $mactable + } +}