Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPv6 support #5

Open
tm-107 opened this issue Oct 1, 2021 · 2 comments
Open

IPv6 support #5

tm-107 opened this issue Oct 1, 2021 · 2 comments

Comments

@tm-107
Copy link

tm-107 commented Oct 1, 2021

Hi,
thanks a lot for the wonderful script!

I've been using your script for a few years now and have made some adjustments to suit my needs (2 Domains with tokens), but implanting IPv6 support is a little too difficult for me ...

So my question is: is there an update planned to support IPv6?

tm-107

@qpirsel
Copy link
Owner

qpirsel commented Oct 1, 2021

I've made a reminder and will have a look at it the next days.

@tm-107
Copy link
Author

tm-107 commented Oct 2, 2021

I made a dirty, but working IPv6 version based on your script. However, there are some limitations:

  • Windows 7 is not supported (i think "[System.Net.Dns]::GetHostByName" doesn't support IPv6).
  • The IPv6 syntax is not checked. It is only checked that $myIP6 is not empty and it is NOT an IPv4 address (Unfortunately, I could not create a functional ipv6 syntax check).

Actually I only changed the service sites, modified CheckIP a little and changed Resolve DNS Name to -Type AAAA.

#requires -version 4

Clear-Host

# (mandatory) adjust your values
$fqdn  = ""
$pwd   = ""
$user  = ""

# (optional) set full path to (writable) logfile and switch logging on ($true) or off ($false)
$myLogFile = "C:\scripts\spdns_update.log"
$logging = $false

# (optional) add or remove IPv6 service sites. NOTE: A service site MUST return a plain IP string WITHOUT any HTML tags!
$myServiceList6 = "http://ip.tyk.nu/"`
                 ,"http://wgetip.com/"`
                 ,"http://ident.me"

### no necessity to edit below this line ###
function log {
    param(
        [Parameter(ValueFromPipeline=$true)]
        $piped
    )

    if ($logging) {
        (Get-Date -Format "yyyy-MM-dd HH:mm:ss").ToString() + " " + `
            $piped | Out-File -FilePath $myLogFile -Append
        }
    # console output
    "$piped"
}

function checkIP ($myServiceAddress) {

    try {
        $myIP = Invoke-WebRequest -Uri $myServiceAddress -UseBasicParsing -TimeoutSec 10 -ErrorAction Stop

        if ( -not ($myIP)) {
            "checkIPv6 ($fqdn) " + "No valid response" | log
            exit 1
        }

        if ($myIP -match '^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$') {
            "checkIPv6 ($fqdn) " + "No valid response (IPv4 was transmitted)" | log
            exit 1
        }

    } catch {
        "checkIPv6 ($fqdn) " + $_.Exception.Message | log
        exit 1
    }

    Return "$myIP"
}

$usedService = Get-Random -InputObject $myServiceList
"checkIP " + "Determine current IPv6 at " + $usedService | log
$currentIP = checkIP $usedService

try {
   if (([System.Environment]::OSVersion.Version.Major -eq 6) -and ([System.Environment]::OSVersion.Version.Minor -eq 1)) {
    "Windows 7/2008R2 currently not suported" | log
        exit 1
    } else {
    "Resolve DNS Name " + "Using native Commandlet" | log
        $ipHostEntry = Resolve-DnsName $fqdn -Type AAAA -ErrorAction Stop
        $registeredIP = $ipHostEntry[0].IPAddress
    }

} catch {
    "Resolve DNS Name ($fqdn) " + $_.Exception.Message | log
    exit 1
}

if ($registeredIP -like $currentIP) {
    "Precheck " + "IP $currentIP already registered ($fqdn)." | log
    exit 0
} else {
    $secpasswd = ConvertTo-SecureString $pwd -AsPlainText -Force
    $myCreds = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)
    $url = "https://update.spdyn.de/nic/update?hostname=$fqdn&myip=$currentIP"

    try {
        $resp = Invoke-WebRequest -Uri $url -Credential $myCreds -UseBasicParsing -ErrorAction Stop        
    } catch {
        "Update DNS ($fqdn) " + $_.Exception.Message | log
        exit 1
    }

    "SPDNS result ($fqdn) " + $resp.Content | log
}

exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants