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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vlbox
gandi-ddns
Commits
598d4b4e
Commit
598d4b4e
authored
Apr 6, 2017
by
arjuan
Browse files
Options
Downloads
Patches
Plain Diff
clarifications
parent
e5d34c2c
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
+7
-7
7 additions, 7 deletions
gandi-ddns.py
with
7 additions
and
7 deletions
gandi-ddns.py
+
7
−
7
View file @
598d4b4e
...
@@ -15,7 +15,7 @@ def get_ip():
...
@@ -15,7 +15,7 @@ def get_ip():
# Could be any service that just gives us a simple raw ASCII IP address (not HTML etc)
# Could be any service that just gives us a simple raw ASCII IP address (not HTML etc)
r
=
requests
.
get
(
'
http://ipv4.myexternalip.com/raw
'
,
timeout
=
3
)
r
=
requests
.
get
(
'
http://ipv4.myexternalip.com/raw
'
,
timeout
=
3
)
except
Exception
:
except
Exception
:
print
(
'
Unab
le to retrieve external IP
address
.
'
)
print
(
'
Fai
le
d
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
'
%
result
.
status_code
)
print
(
'
Failed to retrieve external IP. Server responded with status_code: %d
'
%
result
.
status_code
)
...
@@ -45,10 +45,10 @@ def add_record(url, headers, payload):
...
@@ -45,10 +45,10 @@ def add_record(url, headers, payload):
#Add record
#Add record
r
=
requests
.
post
(
url
,
headers
=
headers
,
json
=
payload
)
r
=
requests
.
post
(
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
addition
failed with status code: %d
'
%
r
.
status_code
)
print
(
r
.
text
)
print
(
r
.
text
)
sys
.
exit
(
2
)
sys
.
exit
(
2
)
print
r
.
text
print
(
'
Zone record added.
'
)
return
r
return
r
...
@@ -71,7 +71,7 @@ def main():
...
@@ -71,7 +71,7 @@ def main():
path
=
os
.
path
.
join
(
SCRIPT_DIR
,
path
)
path
=
os
.
path
.
join
(
SCRIPT_DIR
,
path
)
config
=
read_config
(
path
)
config
=
read_config
(
path
)
if
not
config
:
if
not
config
:
sys
.
exit
(
"
p
lease fill in the
'
config.txt
'
file
"
)
sys
.
exit
(
"
P
lease fill in the
'
config.txt
'
file
.
"
)
for
section
in
config
.
sections
():
for
section
in
config
.
sections
():
...
@@ -86,7 +86,7 @@ def main():
...
@@ -86,7 +86,7 @@ def main():
print
(
url
)
print
(
url
)
#Discover External IP
#Discover External IP
external_ip
=
get_ip
()
external_ip
=
get_ip
()
print
(
'
e
xternal IP is: %s
'
%
external_ip
)
print
(
'
E
xternal 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
]}
...
@@ -97,9 +97,9 @@ def main():
...
@@ -97,9 +97,9 @@ def main():
if
record
.
status_code
==
404
:
if
record
.
status_code
==
404
:
add_record
(
url
,
headers
,
payload
)
add_record
(
url
,
headers
,
payload
)
elif
record
.
status_code
==
200
:
elif
record
.
status_code
==
200
:
print
(
'
c
urrent record is: %s
'
%
json
.
loads
(
record
.
text
)[
'
rrset_values
'
][
0
])
print
(
'
C
urrent 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
'
)
print
(
'
No change in IP address
. Goodbye.
'
)
sys
.
exit
()
sys
.
exit
()
del_record
(
url
,
headers
)
del_record
(
url
,
headers
)
add_record
(
url
,
headers
,
payload
)
add_record
(
url
,
headers
,
payload
)
...
...
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