Diese zwei Funktionen in Powershell  liefern die IP-Adresse aus einer dynamischen DNS. Voraussetzung ist dass z.B. ein Router bei einem Reconnect dem DynDNS-Anbieter die aktuelle IP mitteilt.
Die Skripte teilen die IP nicht dem DynDNs-Anbieter mit!

Diese Funktion liefert durch das Cmdlet Test-Connection IP-Adresse aus einem DynDns-Namen.

# Löst die IP-Adresse aus einem DynDns-Namen auf
Function GET-IPFromDynDns() {
  [CmdletBinding()]
  Param (
    [Parameter(Mandatory=$false,Position=0)]
    [string]$DynDNS 
  )

  $PingResult = Test-Connection -ComputerName $DynDNS -Count 1
  #$return = $PingResult.ProtocolAddress
  $return = $PingResult.IPV4Address.IPAddressToString
  $return
}


Die 2. Funktion liefert via Ping-Befehl die IP-Adresse aus einem DynDns-Namen.

Function GET-IPFromDynDns() {
  [CmdletBinding()]
  Param (
    [Parameter(Mandatory=$false,Position=0)]
    [string]$DynDNS 
  )
  $PingResult = (ping -n 1 $DynDNS)
  if ($PingResult -is [array]) {
    $b = $PingResult[1].LastIndexOfAny("[")+1
    $c = $PingResult[1].LastIndexOfAny("]")
    $Result = $PingResult[1].substring($b, $c - $b)
    $Result
  } else {
    Write-Host $DynDNS "konnte nicht aufgelöst werden!"
 }
}

# Aufruf der Funktion. (Auch mit anderen DynDns-Diensten möglich ;-)
$ip = GET-IPFromDynDNS  "meinesubdomain.dyndns.org"

 

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.