Functions/Generic/Layer3Forwarding.ps1
function Add-AvmRoutingEntry { <# .SYNOPSIS Wiki: https://github.com/Gincules/avmtools/wiki/Add-AvmRoutingEntry .DESCRIPTION Wiki: https://github.com/Gincules/avmtools/wiki/Add-AvmRoutingEntry .NOTES Author: Gincules Website: https://github.com/Gincules/avmtools License: https://github.com/Gincules/avmtools/blob/main/LICENSE .LINK https://github.com/Gincules/avmtools https://github.com/Gincules/avmtools/blob/main/LICENSE #> Param ( [Alias("i")] [Parameter()] [System.Management.Automation.SwitchParameter]$Insecure = $false, [Alias("r")] [Parameter()] [System.Management.Automation.SwitchParameter]$RemoteAccess = $false, [Alias("u")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$Url, [Alias("p")] [Parameter(Mandatory)] [ValidateRange(0,65535)] [System.UInt16]$Port, [Alias("c")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.Management.Automation.PSCredential]$Credential, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewType, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewDestIPAddress, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewDestSubnetMask, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewSourceIPAddress, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewSourceSubnetMask, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewGatewayIPAddress, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewInterface, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewForwardingMetric ) $AvmWebrequestBody = [AvmBody]::new() $AvmWebrequestBody.SoapAction = "urn:dslforum-org:service:Layer3Forwarding:1" $AvmWebrequestBody.UrlPath = "$(if ($RemoteAccess) { "/tr064" })/upnp/control/layer3forwarding" $AvmWebrequestBody.Action = "AddForwardingEntry" $AvmWebrequestBody.InnerBody = @" <s:NewType>{0}</s:NewType> <s:NewDestIPAddress>{1}</s:NewDestIPAddress> <s:NewDestSubnetMask>{2}</s:NewDestSubnetMask> <s:NewSourceIPAddress>{3}</s:NewSourceIPAddress> <s:NewSourceSubnetMask>{4}</s:NewSourceSubnetMask> <s:NewGatewayIPAddress>{5}</s:NewGatewayIPAddress> <s:NewInterface>{6}</s:NewInterface> <s:NewForwardingMetric>{7}</s:NewForwardingMetric> "@ -f $NewType, $NewDestIPAddress, $NewDestSubnetMask, $NewSourceIPAddress, $NewSourceSubnetMask, $NewGatewayIPAddress, $NewInterface, $NewForwardingMetric [System.Collections.Hashtable]$SplatParameters = @{ Insecure = $Insecure Url = $Url Port = $Port Credential = $Credential Body = $AvmWebrequestBody.GenerateBody() SoapAction = $AvmWebrequestBody.GenerateSoapAction() UrlPath = $AvmWebrequestBody.UrlPath XmlResponse = $AvmWebrequestBody.GenerateXmlResponse() } Connect-AvmDevice @SplatParameters } function Enable-AvmRoutingEntry { <# .SYNOPSIS Wiki: https://github.com/Gincules/avmtools/wiki/Enable-AvmRoutingEntry .DESCRIPTION Wiki: https://github.com/Gincules/avmtools/wiki/Enable-AvmRoutingEntry .NOTES Author: Gincules Website: https://github.com/Gincules/avmtools License: https://github.com/Gincules/avmtools/blob/main/LICENSE .LINK https://github.com/Gincules/avmtools https://github.com/Gincules/avmtools/blob/main/LICENSE #> Param ( [Alias("i")] [Parameter()] [System.Management.Automation.SwitchParameter]$Insecure = $false, [Alias("r")] [Parameter()] [System.Management.Automation.SwitchParameter]$RemoteAccess = $false, [Alias("u")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$Url, [Alias("p")] [Parameter(Mandatory)] [ValidateRange(0,65535)] [System.UInt16]$Port, [Alias("c")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.Management.Automation.PSCredential]$Credential, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewDestIPAddress, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewDestSubnetMask, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewSourceIPAddress, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewSourceSubnetMask, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.Byte][System.Boolean]$NewEnable ) $AvmWebrequestBody = [AvmBody]::new() $AvmWebrequestBody.SoapAction = "urn:dslforum-org:service:Layer3Forwarding:1" $AvmWebrequestBody.UrlPath = "$(if ($RemoteAccess) { "/tr064" })/upnp/control/layer3forwarding" $AvmWebrequestBody.Action = "SetForwardingEntryEnable" $AvmWebrequestBody.InnerBody = @" <s:NewDestIPAddress>{0}</s:NewDestIPAddress> <s:NewDestSubnetMask>{1}</s:NewDestSubnetMask> <s:NewSourceIPAddress>{2}</s:NewSourceIPAddress> <s:NewSourceSubnetMask>{3}</s:NewSourceSubnetMask> <s:NewEnable>{4}</s:NewEnable> "@ -f $NewDestIPAddress, $NewDestSubnetMask, $NewSourceIPAddress, $NewSourceSubnetMask, $NewEnable [System.Collections.Hashtable]$SplatParameters = @{ Insecure = $Insecure Url = $Url Port = $Port Credential = $Credential Body = $AvmWebrequestBody.GenerateBody() SoapAction = $AvmWebrequestBody.GenerateSoapAction() UrlPath = $AvmWebrequestBody.UrlPath XmlResponse = $AvmWebrequestBody.GenerateXmlResponse() } Connect-AvmDevice @SplatParameters } function Get-AvmRoutingConnectionService { <# .SYNOPSIS Wiki: https://github.com/Gincules/avmtools/wiki/Get-AvmRoutingConnectionService .DESCRIPTION Wiki: https://github.com/Gincules/avmtools/wiki/Get-AvmRoutingConnectionService .NOTES Author: Gincules Website: https://github.com/Gincules/avmtools License: https://github.com/Gincules/avmtools/blob/main/LICENSE .LINK https://github.com/Gincules/avmtools https://github.com/Gincules/avmtools/blob/main/LICENSE #> Param ( [Alias("i")] [Parameter()] [System.Management.Automation.SwitchParameter]$Insecure = $false, [Alias("r")] [Parameter()] [System.Management.Automation.SwitchParameter]$RemoteAccess = $false, [Alias("u")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$Url, [Alias("p")] [Parameter(Mandatory)] [ValidateRange(0,65535)] [System.UInt16]$Port, [Alias("c")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.Management.Automation.PSCredential]$Credential ) [System.Collections.Hashtable]$SplatParameters = @{ Insecure = $Insecure Url = $Url Port = $Port Credential = $Credential SoapAction = "urn:dslforum-org:service:Layer3Forwarding:1#GetDefaultConnectionService" UrlPath = "$(if ($RemoteAccess) { "/tr064" })/upnp/control/layer3forwarding" XmlResponse = "GetDefaultConnectionServiceResponse" } Connect-AvmDevice @SplatParameters } function Get-AvmRoutingGenericEntry { <# .SYNOPSIS Wiki: https://github.com/Gincules/avmtools/wiki/Get-AvmRoutingGenericEntry .DESCRIPTION Wiki: https://github.com/Gincules/avmtools/wiki/Get-AvmRoutingGenericEntry .NOTES Author: Gincules Website: https://github.com/Gincules/avmtools License: https://github.com/Gincules/avmtools/blob/main/LICENSE .LINK https://github.com/Gincules/avmtools https://github.com/Gincules/avmtools/blob/main/LICENSE #> Param ( [Alias("i")] [Parameter()] [System.Management.Automation.SwitchParameter]$Insecure = $false, [Alias("r")] [Parameter()] [System.Management.Automation.SwitchParameter]$RemoteAccess = $false, [Alias("u")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$Url, [Alias("p")] [Parameter(Mandatory)] [ValidateRange(0,65535)] [System.UInt16]$Port, [Alias("c")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.Management.Automation.PSCredential]$Credential, [Parameter(Mandatory)] [ValidateRange(0,4294967295)] [System.UInt32]$NewForwardingIndex ) $AvmWebrequestBody = [AvmBody]::new() $AvmWebrequestBody.SoapAction = "urn:dslforum-org:service:Layer3Forwarding:1" $AvmWebrequestBody.UrlPath = "$(if ($RemoteAccess) { "/tr064" })/upnp/control/layer3forwarding" $AvmWebrequestBody.Action = "GetGenericForwardingEntry" $AvmWebrequestBody.InnerBody = "<s:NewForwardingIndex>{0}</s:NewForwardingIndex>" -f $NewForwardingIndex [System.Collections.Hashtable]$SplatParameters = @{ Insecure = $Insecure Url = $Url Port = $Port Credential = $Credential Body = $AvmWebrequestBody.GenerateBody() SoapAction = $AvmWebrequestBody.GenerateSoapAction() UrlPath = $AvmWebrequestBody.UrlPath XmlResponse = $AvmWebrequestBody.GenerateXmlResponse() } Connect-AvmDevice @SplatParameters } function Get-AvmRoutingNumberOfEntry { <# .SYNOPSIS Wiki: https://github.com/Gincules/avmtools/wiki/Get-AvmRoutingNumberOfEntry .DESCRIPTION Wiki: https://github.com/Gincules/avmtools/wiki/Get-AvmRoutingNumberOfEntry .NOTES Author: Gincules Website: https://github.com/Gincules/avmtools License: https://github.com/Gincules/avmtools/blob/main/LICENSE .LINK https://github.com/Gincules/avmtools https://github.com/Gincules/avmtools/blob/main/LICENSE #> Param ( [Alias("i")] [Parameter()] [System.Management.Automation.SwitchParameter]$Insecure = $false, [Alias("r")] [Parameter()] [System.Management.Automation.SwitchParameter]$RemoteAccess = $false, [Alias("u")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$Url, [Alias("p")] [Parameter(Mandatory)] [ValidateRange(0,65535)] [System.UInt16]$Port, [Alias("c")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.Management.Automation.PSCredential]$Credential ) [System.Collections.Hashtable]$SplatParameters = @{ Insecure = $Insecure Url = $Url Port = $Port Credential = $Credential SoapAction = "urn:dslforum-org:service:Layer3Forwarding:1#GetForwardNumberOfEntries" UrlPath = "$(if ($RemoteAccess) { "/tr064" })/upnp/control/layer3forwarding" XmlResponse = "GetForwardNumberOfEntriesResponse" } Connect-AvmDevice @SplatParameters } function Get-AvmRoutingSpecificEntry { <# .SYNOPSIS Wiki: https://github.com/Gincules/avmtools/wiki/Get-AvmRoutingSpecificEntry .DESCRIPTION Wiki: https://github.com/Gincules/avmtools/wiki/Get-AvmRoutingSpecificEntry .NOTES Author: Gincules Website: https://github.com/Gincules/avmtools License: https://github.com/Gincules/avmtools/blob/main/LICENSE .LINK https://github.com/Gincules/avmtools https://github.com/Gincules/avmtools/blob/main/LICENSE #> Param ( [Alias("i")] [Parameter()] [System.Management.Automation.SwitchParameter]$Insecure = $false, [Alias("r")] [Parameter()] [System.Management.Automation.SwitchParameter]$RemoteAccess = $false, [Alias("u")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$Url, [Alias("p")] [Parameter(Mandatory)] [ValidateRange(0,65535)] [System.UInt16]$Port, [Alias("c")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.Management.Automation.PSCredential]$Credential, [Parameter()] [ValidateNotNullOrEmpty()] [System.String]$NewDestIPAddress, [Parameter()] [ValidateNotNullOrEmpty()] [System.String]$NewDestSubnetMask, [Parameter()] [ValidateNotNullOrEmpty()] [System.String]$NewSourceIPAddress, [Parameter()] [ValidateNotNullOrEmpty()] [System.String]$NewSourceSubnetMask ) $AvmWebrequestBody = [AvmBody]::new() $AvmWebrequestBody.SoapAction = "urn:dslforum-org:service:Layer3Forwarding:1" $AvmWebrequestBody.UrlPath = "$(if ($RemoteAccess) { "/tr064" })/upnp/control/layer3forwarding" $AvmWebrequestBody.Action = "GetSpecificForwardingEntry" $AvmWebrequestBody.InnerBody = @" <s:NewDestIPAddress>{0}</s:NewDestIPAddress> <s:NewDestSubnetMask>{1}</s:NewDestSubnetMask> <s:NewSourceIPAddress>{2}</s:NewSourceIPAddress> <s:NewSourceSubnetMask>{3}</s:NewSourceSubnetMask> "@ -f $NewDestIPAddress, $NewDestSubnetMask, $NewSourceIPAddress, $NewSourceSubnetMask [System.Collections.Hashtable]$SplatParameters = @{ Insecure = $Insecure Url = $Url Port = $Port Credential = $Credential Body = $AvmWebrequestBody.GenerateBody() SoapAction = $AvmWebrequestBody.GenerateSoapAction() UrlPath = $AvmWebrequestBody.UrlPath XmlResponse = $AvmWebrequestBody.GenerateXmlResponse() } Connect-AvmDevice @SplatParameters } function Remove-AvmRoutingEntry { <# .SYNOPSIS Wiki: https://github.com/Gincules/avmtools/wiki/Remove-AvmRoutingEntry .DESCRIPTION Wiki: https://github.com/Gincules/avmtools/wiki/Remove-AvmRoutingEntry .NOTES Author: Gincules Website: https://github.com/Gincules/avmtools License: https://github.com/Gincules/avmtools/blob/main/LICENSE .LINK https://github.com/Gincules/avmtools https://github.com/Gincules/avmtools/blob/main/LICENSE #> Param ( [Alias("i")] [Parameter()] [System.Management.Automation.SwitchParameter]$Insecure = $false, [Alias("r")] [Parameter()] [System.Management.Automation.SwitchParameter]$RemoteAccess = $false, [Alias("u")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$Url, [Alias("p")] [Parameter(Mandatory)] [ValidateRange(0,65535)] [System.UInt16]$Port, [Alias("c")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.Management.Automation.PSCredential]$Credential, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewDestIPAddress, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewDestSubnetMask, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewSourceIPAddress, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewSourceSubnetMask ) $AvmWebrequestBody = [AvmBody]::new() $AvmWebrequestBody.SoapAction = "urn:dslforum-org:service:Layer3Forwarding:1" $AvmWebrequestBody.UrlPath = "$(if ($RemoteAccess) { "/tr064" })/upnp/control/layer3forwarding" $AvmWebrequestBody.Action = "DeleteForwardingEntry" $AvmWebrequestBody.InnerBody = @" <s:NewDestIPAddress>{0}</s:NewDestIPAddress> <s:NewDestSubnetMask>{1}</s:NewDestSubnetMask> <s:NewSourceIPAddress>{2}</s:NewSourceIPAddress> <s:NewSourceSubnetMask>{3}</s:NewSourceSubnetMask> "@ -f $NewDestIPAddress, $NewDestSubnetMask, $NewSourceIPAddress, $NewSourceSubnetMask [System.Collections.Hashtable]$SplatParameters = @{ Insecure = $Insecure Url = $Url Port = $Port Credential = $Credential Body = $AvmWebrequestBody.GenerateBody() SoapAction = $AvmWebrequestBody.GenerateSoapAction() UrlPath = $AvmWebrequestBody.UrlPath XmlResponse = $AvmWebrequestBody.GenerateXmlResponse() } Connect-AvmDevice @SplatParameters } function Set-AvmRoutingConnectionService { <# .SYNOPSIS Wiki: https://github.com/Gincules/avmtools/wiki/Set-AvmRoutingConnectionService .DESCRIPTION Wiki: https://github.com/Gincules/avmtools/wiki/Set-AvmRoutingConnectionService .NOTES Author: Gincules Website: https://github.com/Gincules/avmtools License: https://github.com/Gincules/avmtools/blob/main/LICENSE .LINK https://github.com/Gincules/avmtools https://github.com/Gincules/avmtools/blob/main/LICENSE #> Param ( [Alias("i")] [Parameter()] [System.Management.Automation.SwitchParameter]$Insecure = $false, [Alias("r")] [Parameter()] [System.Management.Automation.SwitchParameter]$RemoteAccess = $false, [Alias("u")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$Url, [Alias("p")] [Parameter(Mandatory)] [ValidateRange(0,65535)] [System.UInt16]$Port, [Alias("c")] [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.Management.Automation.PSCredential]$Credential, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [System.String]$NewDefaultConnectionService ) $AvmWebrequestBody = [AvmBody]::new() $AvmWebrequestBody.SoapAction = "urn:dslforum-org:service:Layer3Forwarding:1" $AvmWebrequestBody.UrlPath = "$(if ($RemoteAccess) { "/tr064" })/upnp/control/layer3forwarding" $AvmWebrequestBody.Action = "SetDefaultConnectionService" $AvmWebrequestBody.InnerBody = "<s:NewDefaultConnectionService>{0}</s:NewDefaultConnectionService>" -f $NewDefaultConnectionService [System.Collections.Hashtable]$SplatParameters = @{ Insecure = $Insecure Url = $Url Port = $Port Credential = $Credential Body = $AvmWebrequestBody.GenerateBody() SoapAction = $AvmWebrequestBody.GenerateSoapAction() UrlPath = $AvmWebrequestBody.UrlPath XmlResponse = $AvmWebrequestBody.GenerateXmlResponse() } Connect-AvmDevice @SplatParameters } |