Skip to content

Commit

Permalink
add: 添加 ipv4-local模式
Browse files Browse the repository at this point in the history
  • Loading branch information
scjtqs committed Mar 9, 2022
1 parent 7f8b5f2 commit 8984638
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GO Version: go1.17.6
Usage:
./ddns -id 1 -token xxxxx
./ddns -id 1 -token xxxxx -type ipv4 -sub www -domain scjtqs.com
./ddns -id 1 -token xxxxx -type ipv6 -sub www -domain scjtqs.com -extscript /path/ipv6.sh
./ddns -id 1 -token xxxxx -type ipv6 -sub ipv6 -domain scjtqs.com -extscript /path/ipv6.sh

参数说明:
-domain string
Expand All @@ -28,6 +28,7 @@ Usage:
使用类型:
default 默认类型 使用公网ipv4地址替换web网站上配置的所有的域名信息
ipv4 独立使用。更新 sub.domain 的域名的ipv4地址,默认情况下为使用当前网络的公网IP
ipv4-local 独立使用。更新 sub.domain 的域名的ipv4地址,默认情况下为使用当前设备的 内网ipv4地址
ipv6 独立使用。更新 sub.domain 的域名的ipv6地址,默认情况下为使用当前设备对外的IPV6地址
(default "default")
-v show version info
Expand Down
22 changes: 22 additions & 0 deletions app/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func (c *Client) Run() {
switch c.Config.Type {
case config.TYPE_IPV4:
c.ipv4Run()
case config.TYPE_IPV4_LOCAL:
c.ipv4LocalRun()
case config.TYPE_IPV6:
c.ipv6Run()
case config.TYPE_DEFAULT:
Expand Down Expand Up @@ -60,6 +62,26 @@ func (c *Client) ipv4Run() {
fmt.Printf("ipv4 rsp:%s", rsp)
}

// ipv4LocalRun ipv4 lan模式运行
func (c *Client) ipv4LocalRun() {
var (
ipv4 string
err error
)
switch c.Config.ExtScript {
case "":
ipv4, err = GetOutBoundIP()
default:
ipv4, err = Command(c.Config.ExtScript)
}
if err != nil {
panic(err)
}
url := fmt.Sprintf("%s/ddns/client/ipv4?id=%d&token=%s&sub=%s&domain=%s&ipv4=%s", config.BASE_URL, c.Config.UserID, c.Config.Token, c.Config.Sub, c.Config.Domain, ipv4)
rsp, err := Get(url)
fmt.Printf("ipv4-local rsp:%s", rsp)
}

// ipv6Run ipv6模式运行
func (c *Client) ipv6Run() {
var (
Expand Down
8 changes: 5 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
)

const (
TYPE_IPV4 = "ipv4"
TYPE_IPV6 = "ipv6"
TYPE_DEFAULT = "default" // 走默认接口 ipv4的批量修改一批sub为同一公网ip
TYPE_IPV4 = "ipv4"
TYPE_IPV4_LOCAL = "ipv4-local" // ipv4 lan口的内网地址
TYPE_IPV6 = "ipv6"
TYPE_DEFAULT = "default" // 走默认接口 ipv4的批量修改一批sub为同一公网ip
)

const (
Expand Down Expand Up @@ -50,6 +51,7 @@ func Parse() *Config {
flag.StringVar(&c.Type, "type", "default", `使用类型:
default 默认类型 使用公网ipv4地址替换web网站上配置的所有的域名信息
ipv4 独立使用。更新 sub.domain 的域名的ipv4地址,默认情况下为使用当前网络的公网IP
ipv4-local 独立使用。更新 sub.domain 的域名的ipv4地址,默认情况下为使用当前设备的 内网ipv4地址
ipv6 独立使用。更新 sub.domain 的域名的ipv6地址,默认情况下为使用当前设备对外的IPV6地址
`)
flag.StringVar(&c.ExtScript, "extscript", "", "使用额外脚本来获取ipv4/ipv6地址。不使用留空")
Expand Down

0 comments on commit 8984638

Please sign in to comment.