自动获取本机 IP 并更新 CDN 源站地址,同时支持 IPV4 和 IPV6。
-
Cloudflare
-
Alibaba Cloud ECDN
-
Tencent Cloud DCDN
See example
./ddns4cdn -c config.toml
Tips for developers using macOS:
You don't need Xcode (but still need to install command line tools) to build executables and libraries (including Swift).
I created this project without opening Xcode at all, you can do the same.
Xcode sucks. It doesn't provide a human-readable configuration file. When I search on Google for development problems about macOS, most of the results are about Xcode (even on Stack Overflow). Using the mouse to click buttons is not a good way to develop. It is not efficient and not reproducible. I don't want to use a tool that I don't know how it works.
go build -o build/ddns4cdn[.exe] ./src
Set GOOS
and GOARCH
to build for other platforms.
-
Mingw-w64 (GCC, required for
go build
)WinLibs's build is recommended, tested with MCF and UCRT.
-
Microsoft C Build Tools (MSVC, optional)
go build
doesn't support MSVC, but you can use MSVC to build exe and dll.
GCC or Clang
go build
can use GCC or Clang, set CC
to switch.
go build -o build/ddns4cdn.a -buildmode=c-archive ./src/cgo/go
# C
gcc -o build/ddns4cdn_c src/cgo/c/main.c build/ddns4cdn.a
# C
g -o build/ddns4cdn_cpp src/cgo/cpp/main.cc build/ddns4cdn.a
# C
clang -o build/ddns4cdn_c src/cgo/c/main.c build/ddns4cdn.a -framework CoreFoundation -framework Security -lresolv
# C
clang -o build/ddns4cdn_cpp src/cgo/cpp/main.cc build/ddns4cdn.a -framework CoreFoundation -framework Security -lresolv
# Objective-C
clang -o build/ddns4cdn_objc src/cgo/objc/main.m build/ddns4cdn.a -framework Foundation -framework Security -lresolv
# only supports amd64
& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64 -HostArch amd64
# C
cl /MD /Fe"build\ddns4cdn_msvc_c.exe" /Fo"build\ddns4cdn_msvc_c.obj" src\cgo\c\main.c /link build\ddns4cdn.a
# C
cl /EHsc /MD /Fe"build\ddns4cdn_msvc_cpp.exe" /Fo"build\ddns4cdn_msvc_cpp.obj" src\cgo\cpp\main.cc /link build\ddns4cdn.a
go build -o build/ddns4cdn.so -buildmode=c-shared ./src/cgo/go
# C
gcc -o build/ddns4cdn_dl_c src/cgo/c/main.c build/ddns4cdn.so
# C
g -o build/ddns4cdn_dl_cpp src/cgo/cpp/main.cc build/ddns4cdn.so
# C
clang -o build/ddns4cdn_dl_c src/cgo/c/main.c build/ddns4cdn.so
# C
clang -o build/ddns4cdn_dl_cpp src/cgo/cpp/main.cc build/ddns4cdn.so
# Objective-C
clang -o build/ddns4cdn_dl_objc src/cgo/objc/main.m build/ddns4cdn.so -framework Foundation
# set DYLD_LIBRARY_PATH to load shared library
export DYLD_LIBRARY_PATH=$(realpath build)
Building a dynamic-link library (.dll) requires a static library (.a) as a link file.
See the previous section for how to build a static library.
```powershell
# only supports amd64
& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64 -HostArch amd64
# DLL
cl /LD /MD /Fe"build\ddns4cdn.dll" /Fo"build\ddns4cdn.obj" src\cgo\msvc\ddns4cdn.c /link /DEF:src\cgo\msvc\ddns4cdn.def build\ddns4cdn.a
# C
cl /DNO_CGO_LIB /Fe"build\ddns4cdn_msvc_dl_c.exe" /Fo"build\ddns4cdn_msvc_dl_c.obj" src\cgo\c\main.c /link build\ddns4cdn.lib
# C
cl /DNO_CGO_LIB /EHsc /Fe"build\ddns4cdn_msvc_dl_cpp.exe" /Fo"build\ddns4cdn_msvc_dl_cpp.obj" src\cgo\cpp\main.cc /link build\ddns4cdn.lib
Compiling C# code requires a dynamic-link library (.dll).
See the previous section for how to build a dll.
cd src/cgo/csharp
dotnet publish
cd src/cgo/swift
# the output binary is .build/release/ddns4cdn
# and .build/release/ddns4cdn_dl
swift build -c release
# to use ddns4cdn_dl, set DYLD_LIBRARY_PATH to load shared library
# ddns4cdn linked a static library, so you don't need to set it
export DYLD_LIBRARY_PATH=$(realpath ../../../build)
Android:
Android SDK Command-Line Tools
iOS:
cd src/gomobile
# Android
gomobile bind -o ../../build/ddns4cdn.aar -target android -javapkg ddns4cdn -androidapi 34
# iOS and macOS
gomobile bind -o ../../build/Ddns4cdn.xcframework -target ios,macos -prefix Ddns4cdn -iosversion 17