2022-12-04 10:40:18 +01:00
|
|
|
## The *list-fritzbox-devices.ps1* Script
|
2021-11-08 21:36:42 +01:00
|
|
|
|
2022-02-10 09:01:07 +01:00
|
|
|
This PowerShell script lists FRITZ!Box's known devices.
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
## Parameters
|
|
|
|
```powershell
|
2023-05-26 12:20:18 +02:00
|
|
|
/home/mf/Repos/PowerShell/Scripts/list-fritzbox-devices.ps1 [[-Username] <String>] [[-Password] <String>] [<CommonParameters>]
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
-Username <String>
|
|
|
|
Specifies the user name to FRITZ!Box
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 1
|
|
|
|
Default value
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
-Password <String>
|
|
|
|
Specifies the password to FRITZ!Box
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 2
|
|
|
|
Default value
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
|
|
|
## Example
|
|
|
|
```powershell
|
|
|
|
PS> ./list-fritzbox-devices
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## Notes
|
2022-11-17 19:46:02 +01:00
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-11-08 21:36:42 +01:00
|
|
|
|
|
|
|
## Related Links
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
2022-11-17 20:02:26 +01:00
|
|
|
## Source Code
|
2022-11-17 20:05:34 +01:00
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Lists FRITZ!Box's known devices
|
|
|
|
.DESCRIPTION
|
|
|
|
This PowerShell script lists FRITZ!Box's known devices.
|
|
|
|
.PARAMETER Username
|
|
|
|
Specifies the user name to FRITZ!Box
|
|
|
|
.PARAMETER Password
|
|
|
|
Specifies the password to FRITZ!Box
|
|
|
|
.EXAMPLE
|
|
|
|
PS> ./list-fritzbox-devices
|
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
#>
|
|
|
|
|
|
|
|
#Requires -Version 3
|
|
|
|
|
|
|
|
param([string]$Username = "", [string]$Password = "")
|
|
|
|
|
|
|
|
if ($Username -eq "") { $Username = read-host "Enter username for FRITZ!Box" }
|
|
|
|
if ($Password -eq "") { $Password = read-host "Enter password for FRITZ!Box" }
|
|
|
|
|
|
|
|
write-progress "Contacting FRITZ!Box ..."
|
|
|
|
[string]$HostURL = "https://fritz.box:49443"
|
|
|
|
[string]$SOAPAction="urn:dslforum-org:service:Hosts:1#X_AVM-DE_GetHostListPath"
|
|
|
|
[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>
|
|
|
|
"@
|
|
|
|
|
|
|
|
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
|
|
|
|
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword
|
|
|
|
|
|
|
|
$XmlResult = invoke-restMethod `
|
|
|
|
-Method POST `
|
|
|
|
-Headers @{'SOAPAction'=($SOAPAction)} `
|
|
|
|
-Uri ($HostURL+"/upnp/control/hosts") `
|
|
|
|
-Credential $Credentials `
|
|
|
|
-ContentType 'text/xml' `
|
|
|
|
-Body $SOAPrequest
|
|
|
|
|
|
|
|
$HostList = invoke-restMethod -Uri ($HostURL+($XmlResult.Envelope.Body.'X_AVM-DE_GetHostListPathResponse'.'NewX_AVM-DE_HostListPath'))
|
|
|
|
|
|
|
|
$HostTable = $HostList.List.Item.GetEnumerator()
|
|
|
|
|
|
|
|
$HostTable | format-table -property Active,IPAddress,MACAddress,HostName,InterfaceType,X_AVM-DE_Speed
|
|
|
|
|
|
|
|
exit 0 # success
|
2022-11-17 20:05:34 +01:00
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2021-11-08 21:36:42 +01:00
|
|
|
*Generated by convert-ps2md.ps1 using the comment-based help of list-fritzbox-devices.ps1*
|