Page Menu
Home
VyOS Platform
Search
Configure Global Search
Log In
Files
F35450738
dynamic_dns_status.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
dynamic_dns_status.py
View Options
#!/usr/bin/env python3
import
jinja2
import
sys
import
time
from
vyos.config
import
Config
cache_file
=
r'/var/cache/ddclient/ddclient.cache'
OUT_TMPL_SRC
=
"""
{%- for entry in hosts -%}
ip address : {{ entry.ip }}
host-name : {{ entry.host }}
last update : {{ entry.time }}
update-status: {{ entry.status }}
{% endfor -%}
"""
if
__name__
==
'__main__'
:
# Do nothing if service is not configured
c
=
Config
()
if
not
c
.
exists_effective
(
'service dns dynamic'
):
print
(
"Dynamic DNS not configured"
)
sys
.
exit
(
0
)
data
=
{
'hosts'
:
[]
}
with
open
(
cache_file
,
'r'
)
as
f
:
for
line
in
f
:
if
line
.
startswith
(
'#'
):
continue
outp
=
{
'host'
:
''
,
'ip'
:
''
,
'time'
:
''
}
if
'host='
in
line
:
host
=
line
.
split
(
'host='
)[
1
]
if
host
:
outp
[
'host'
]
=
host
.
split
(
','
)[
0
]
if
'ip='
in
line
:
ip
=
line
.
split
(
'ip='
)[
1
]
if
ip
:
outp
[
'ip'
]
=
ip
.
split
(
','
)[
0
]
if
'atime='
in
line
:
atime
=
line
.
split
(
'atime='
)[
1
]
if
atime
:
tmp
=
atime
.
split
(
','
)[
0
]
outp
[
'time'
]
=
time
.
strftime
(
"%Y-%m-
%d
%H:%M:%S"
,
time
.
gmtime
(
int
(
tmp
,
base
=
10
)))
if
'status='
in
line
:
status
=
line
.
split
(
'status='
)[
1
]
if
status
:
outp
[
'status'
]
=
status
.
split
(
','
)[
0
]
data
[
'hosts'
]
.
append
(
outp
)
tmpl
=
jinja2
.
Template
(
OUT_TMPL_SRC
)
print
(
tmpl
.
render
(
data
))
File Metadata
Details
Attached
Mime Type
text/x-script.python
Expires
Tue, Dec 9, 10:51 PM (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3083976
Default Alt Text
dynamic_dns_status.py (1 KB)
Attached To
Mode
rVYOSONEX vyos-1x
Attached
Detach File
Event Timeline
Log In to Comment