Private GIT
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gandi-ddns
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vlbox
gandi-ddns
Commits
b93170ea
Commit
b93170ea
authored
7 years ago
by
Jannik Steinbach
Browse files
Options
Downloads
Patches
Plain Diff
Ported to python3 and fixed indentation error
parent
f1610dd3
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
gandi-ddns.py
+8
-8
8 additions, 8 deletions
gandi-ddns.py
with
8 additions
and
8 deletions
gandi-ddns.py
+
8
−
8
View file @
b93170ea
import
C
onfig
P
arser
as
configparser
import
c
onfig
p
arser
as
configparser
import
sys
import
sys
import
os
import
os
import
requests
import
requests
...
@@ -18,7 +18,7 @@ def get_ip():
...
@@ -18,7 +18,7 @@ def get_ip():
print
(
'
Failed to retrieve external IP.
'
)
print
(
'
Failed to retrieve external IP.
'
)
sys
.
exit
(
2
)
sys
.
exit
(
2
)
if
r
.
status_code
!=
200
:
if
r
.
status_code
!=
200
:
print
(
'
Failed to retrieve external IP. Server responded with status_code: %d
'
%
r
.
status_code
)
print
(
(
'
Failed to retrieve external IP. Server responded with status_code: %d
'
%
r
.
status_code
)
)
sys
.
exit
(
2
)
sys
.
exit
(
2
)
ip
=
r
.
text
.
rstrip
()
# strip \n and any trailing whitespace
ip
=
r
.
text
.
rstrip
()
# strip \n and any trailing whitespace
...
@@ -45,8 +45,8 @@ def update_record(url, headers, payload):
...
@@ -45,8 +45,8 @@ def update_record(url, headers, payload):
#Add record
#Add record
r
=
requests
.
put
(
url
,
headers
=
headers
,
json
=
payload
)
r
=
requests
.
put
(
url
,
headers
=
headers
,
json
=
payload
)
if
r
.
status_code
!=
201
:
if
r
.
status_code
!=
201
:
print
(
'
Record update failed with status code: %d
'
%
r
.
status_code
)
print
(
(
'
Record update failed with status code: %d
'
%
r
.
status_code
)
)
print
(
r
.
text
)
print
(
(
r
.
text
)
)
sys
.
exit
(
2
)
sys
.
exit
(
2
)
print
(
'
Zone record updated.
'
)
print
(
'
Zone record updated.
'
)
...
@@ -74,7 +74,7 @@ def main():
...
@@ -74,7 +74,7 @@ def main():
print
(
url
)
print
(
url
)
#Discover External IP
#Discover External IP
external_ip
=
get_ip
()
external_ip
=
get_ip
()
print
(
'
External IP is: %s
'
%
external_ip
)
print
(
(
'
External IP is: %s
'
%
external_ip
)
)
#Prepare record
#Prepare record
payload
=
{
'
rrset_ttl
'
:
config
.
get
(
section
,
'
ttl
'
),
'
rrset_values
'
:
[
external_ip
]}
payload
=
{
'
rrset_ttl
'
:
config
.
get
(
section
,
'
ttl
'
),
'
rrset_values
'
:
[
external_ip
]}
...
@@ -83,7 +83,7 @@ def main():
...
@@ -83,7 +83,7 @@ def main():
record
=
get_record
(
url
,
headers
)
record
=
get_record
(
url
,
headers
)
if
record
.
status_code
==
200
:
if
record
.
status_code
==
200
:
print
(
'
Current record value is: %s
'
%
json
.
loads
(
record
.
text
)[
'
rrset_values
'
][
0
])
print
(
(
'
Current record value is: %s
'
%
json
.
loads
(
record
.
text
)[
'
rrset_values
'
][
0
])
)
if
(
json
.
loads
(
record
.
text
)[
'
rrset_values
'
][
0
]
==
external_ip
):
if
(
json
.
loads
(
record
.
text
)[
'
rrset_values
'
][
0
]
==
external_ip
):
print
(
'
No change in IP address. Goodbye.
'
)
print
(
'
No change in IP address. Goodbye.
'
)
sys
.
exit
()
sys
.
exit
()
...
...
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