PowerShell/Scripts/list-fritzbox-devices.ps1

55 lines
1.7 KiB
PowerShell
Raw Normal View History

2021-09-27 10:38:12 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
2021-09-24 17:19:49 +02:00
Lists FRITZ!Box's known devices
2021-10-04 21:29:23 +02:00
.DESCRIPTION
2021-10-15 23:09:08 +02:00
This script lists FRITZ!Box's known devices.
.PARAMETER Username
Specifies the user name to FRITZ!Box
.PARAMETER Password
Specifies the password to FRITZ!Box
2021-07-13 21:10:02 +02:00
.EXAMPLE
2021-09-24 17:19:49 +02:00
PS> ./list-fritzbox-devices
2021-08-29 17:50:03 +02:00
.NOTES
Author: Markus Fleschutz · License: CC0
2021-07-13 21:10:02 +02:00
.LINK
https://github.com/fleschutz/PowerShell
2021-01-03 12:20:33 +01:00
#>
2021-09-11 11:37:22 +02:00
#Requires -Version 3
2021-07-15 15:51:22 +02:00
param([string]$Username = "", [string]$Password = "")
2021-04-21 19:53:52 +02:00
if ($Username -eq "") { $Username = read-host "Enter username for FRITZ!Box" }
if ($Password -eq "") { $Password = read-host "Enter password for FRITZ!Box" }
2021-02-18 20:17:55 +01:00
2021-01-03 17:27:38 +01:00
write-progress "Contacting FRITZ!Box ..."
[string]$HostURL = "https://fritz.box:49443"
[string]$SOAPAction="urn:dslforum-org:service:Hosts:1#X_AVM-DE_GetHostListPath"
2021-01-03 12:20:33 +01:00
[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>
"@
2021-01-03 17:27:38 +01:00
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword
2021-01-03 12:20:33 +01:00
2021-01-03 17:27:38 +01:00
$XmlResult = invoke-restMethod `
2021-01-03 12:20:33 +01:00
-Method POST `
2021-01-03 17:27:38 +01:00
-Headers @{'SOAPAction'=($SOAPAction)} `
-Uri ($HostURL+"/upnp/control/hosts") `
-Credential $Credentials `
2021-01-03 12:20:33 +01:00
-ContentType 'text/xml' `
-Body $SOAPrequest
2021-01-03 17:27:38 +01:00
$HostList = invoke-restMethod -Uri ($HostURL+($XmlResult.Envelope.Body.'X_AVM-DE_GetHostListPathResponse'.'NewX_AVM-DE_HostListPath'))
2021-01-03 12:20:33 +01:00
2021-01-03 17:27:38 +01:00
$HostTable = $HostList.List.Item.GetEnumerator()
2021-01-03 12:20:33 +01:00
2021-01-03 17:27:38 +01:00
$HostTable | format-table -property Active,IPAddress,MACAddress,HostName,InterfaceType,X_AVM-DE_Speed
2021-01-03 12:20:33 +01:00
2021-09-27 10:09:45 +02:00
exit 0 # success