这个代码保存成ddnsv6.fm20.cn.ps1就能正常运行了
function Get-GUID() {
# 指定注册表路径
$path = "HKLM:\Software\Firadio\ddnsv6.fm20.cn"
# 如果注册表路径不存在则创建
if (-not (Test-Path $path)) {
New-Item -Force -Path $path >$null
}
# 尝试获取注册表中的 "guid" 属性值
$v = Get-ItemProperty -ErrorAction SilentlyContinue -Path $path -Name "guid"
if ($v) {
return $v.guid
}
# 如果 "guid" 属性不存在,则生成一个新的 GUID 并写入注册表
$guid = [System.Guid]::NewGuid().Guid
Set-ItemProperty -Path $path -Name "guid" -Value $guid
return $guid
}
# 创建一个 UDP 客户端并发送数据
$udpClient = New-Object System.Net.Sockets.UdpClient([System.Net.Sockets.AddressFamily]::InterNetworkV6)
$data = Get-GUID
$msg = [Text.Encoding]::UTF8.GetBytes($data)
# 循环发送数据
while ($true) {
$udpClient.Send($msg, $msg.Length, 'ddnsv6.fm20.cn', 12345)
Start-Sleep -Seconds 1
}
# 关闭 UDP 客户端
$udpClient.Close()
但有些电脑运行后会提示错误
ddnsv6.fm20.cn.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
+ CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess
所以下面我改成bat,确保大多数Windows系统都能正常能运行。
复制下面这个代码并保存成“ddnsv6.fm20.cn.bat”就能正常运行了
powershell -c "function Get-GUID(){$path=\"HKLM:\Software\Firadio\ddnsv6.fm20.cn\";if (-not (Test-Path $path)) {New-Item -Force -Path $path >$null;}$v=Get-ItemProperty -ErrorAction SilentlyContinue -Path $path -Name \"guid\";if ($v) {return $v.guid;}$guid=[System.Guid]::NewGuid().Guid;Set-ItemProperty -Path \"HKLM:\Software\Firadio\ddnsv6.fm20.cn\" -Name \"guid\" -Value $guid;return $guid;}$udpClient=New-Object System.Net.Sockets.UdpClient([System.Net.Sockets.AddressFamily]::InterNetworkV6);$data=Get-GUID;$msg=[Text.Encoding]::UTF8.GetBytes($data);while($true){$udpClient.Send($msg,$msg.Length,'ddnsv6.fm20.cn',12345);Start-Sleep -Seconds 1;}$udpClient.Close();"
标签:cn,Windows,Path,ipv6,DDNS,fm20,path,guid,ddnsv6
From: https://www.cnblogs.com/xiangxisheng/p/17991720