Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dyndnsd-client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
dyndnsd-client
Commits
6bde3ce6
Commit
6bde3ce6
authored
7 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Initial working version
parent
1b059c77
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+97
-0
97 additions, 0 deletions
.gitignore
README.md
+4
-0
4 additions, 0 deletions
README.md
config-sample.json
+11
-0
11 additions, 0 deletions
config-sample.json
dyndnsd-client.go
+112
-0
112 additions, 0 deletions
dyndnsd-client.go
with
224 additions
and
0 deletions
.gitignore
0 → 100644
+
97
−
0
View file @
6bde3ce6
# Created by .ignore support plugin (hsz.mobi)
### User config
config.json
### Go template
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
### macOS template
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
This diff is collapsed.
Click to expand it.
README.md
0 → 100644
+
4
−
0
View file @
6bde3ce6
dyndnsd-client
==============
Client for the
[
`dyndnsd`
](
https://github.com/cmur2/dyndnsd
)
daemon.
This diff is collapsed.
Click to expand it.
config-sample.json
0 → 100644
+
11
−
0
View file @
6bde3ce6
{
"username"
:
""
,
"password"
:
""
,
"protocol"
:
"http"
,
"host"
:
""
,
"port"
:
8245
,
"path"
:
""
,
"dns_hostname"
:
""
,
"ipv4_endpoint"
:
"http://whatismyip.akamai.com/"
,
"ipv6_endpoint"
:
"http://ipv6.whatismyip.akamai.com/"
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
dyndnsd-client.go
+
112
−
0
View file @
6bde3ce6
package
main
package
main
import
(
"fmt"
"github.com/joshbetz/config"
"io/ioutil"
"net/http"
"net/url"
)
var
(
cfg
*
config
.
Config
ipv4Endpoint
string
ipv6Endpoint
string
)
// Parse config
func
init
()
{
cfg
=
config
.
New
(
"config.json"
)
cfg
.
Get
(
"ipv4_endpoint"
,
&
ipv4Endpoint
)
cfg
.
Get
(
"ipv6_endpoint"
,
&
ipv6Endpoint
)
}
// Do the update!
func
main
()
{
func
main
()
{
// Base URL
endpoint
,
err
:=
buildEndpointUrl
()
if
err
!=
nil
{
return
}
// IPv4 is required
ipv4
,
err
:=
getUrl
(
ipv4Endpoint
)
if
err
==
nil
{
query
:=
endpoint
.
Query
()
query
.
Set
(
"myip"
,
ipv4
)
endpoint
.
RawQuery
=
query
.
Encode
()
}
else
{
return
}
fmt
.
Println
(
endpoint
)
// IPv6 is optional
ipv6
,
err
:=
getUrl
(
ipv6Endpoint
)
if
err
==
nil
{
query
:=
endpoint
.
Query
()
query
.
Set
(
"myip6"
,
ipv6
)
endpoint
.
RawQuery
=
query
.
Encode
()
}
// Send the update
dyndns
,
err
:=
getUrl
(
endpoint
.
String
())
if
err
!=
nil
{
return
}
// TODO: better formatting
fmt
.
Println
(
dyndns
)
}
// Build endpoint URL from configuration
func
buildEndpointUrl
()
(
*
url
.
URL
,
error
)
{
var
username
string
var
password
string
var
protocol
string
var
host
string
var
port
int
var
path
string
var
hostname
string
cfg
.
Get
(
"username"
,
&
username
)
cfg
.
Get
(
"password"
,
&
password
)
cfg
.
Get
(
"protocol"
,
&
protocol
)
cfg
.
Get
(
"host"
,
&
host
)
cfg
.
Get
(
"port"
,
&
port
)
cfg
.
Get
(
"path"
,
&
path
)
cfg
.
Get
(
"dns_hostname"
,
&
hostname
)
daemonUrl
,
err
:=
url
.
Parse
(
""
)
if
err
!=
nil
{
return
nil
,
err
}
daemonUrl
.
Scheme
=
protocol
daemonUrl
.
Host
=
fmt
.
Sprintf
(
"%s:%d"
,
host
,
port
)
daemonUrl
.
Path
=
path
userInfo
:=
url
.
UserPassword
(
username
,
password
)
daemonUrl
.
User
=
userInfo
query
:=
daemonUrl
.
Query
()
query
.
Set
(
"hostname"
,
hostname
)
daemonUrl
.
RawQuery
=
query
.
Encode
()
return
daemonUrl
,
nil
}
// Retrieve given URL
func
getUrl
(
url
string
)
(
string
,
error
)
{
resp
,
err
:=
http
.
Get
(
url
)
if
err
!=
nil
{
return
""
,
err
}
defer
resp
.
Body
.
Close
()
respBody
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
""
,
err
}
respBodyString
:=
string
(
respBody
)
return
respBodyString
,
nil
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment