dyndns

Check-in [c0cb1c4af6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Some interim work for a Python3 client; micropython on the ESP32 is what I have specifically in mind.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:c0cb1c4af60000b49300acdeec3132247b3fa1f593a254a1c7980d34587e9e11
User & Date: ajv-899-334-8894@vsta.org 2017-06-15 04:46:51
Context
2017-06-15
04:52
Merge branch 'master' of https://github.com/vandys/dyndns check-in: bdad547ae1 user: ajv-899-334-8894@vsta.org tags: master, trunk
04:46
Some interim work for a Python3 client; micropython on the ESP32 is what I have specifically in mind. check-in: c0cb1c4af6 user: ajv-899-334-8894@vsta.org tags: master, trunk
04:45
More details in the doc check-in: 99d81d3502 user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added client3.py.

















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#
# client3.py
#	Dynamic DNS client, micropython/Python3 variant
#
# Sends a UDP packet; it gets our global source address, and we
#  sign the request so it'll register our current address against
#  a hostname under the dynamic IP subzone.
#
# This is intended to run on an embedded device with Micropython, thus
#  the (lame) Python3 dialect.
#
import socket, hashlib, sys, json, os
import network

#
# Fill these in for your target
#

# These concern the Wifi connection
#
# SSID
ssid = "TBD"
# Its password
ssid_pw = "TBD"
#
wlan = network.WLAN(network.STA_IF)
wlan.active(True)wlan.active(True)
wlan.connect(ssid, ssid_pw)
while not wlan.isconnected():
    time.sleep(0.25)
print("Wifi up: " + wlan.ifconfig())

# These concern the dynamic DNS server:
#
# Server:port to send update
server = "TBD"
port = TBD
# Who we update
host = "TBD"
# How we prove we're OK
password = "TBD"

# XOR a byte range into one half its size
def fold(buf):
    l = len(buf)/2
    return bytes((c1 ^ c2)
	for c1,c2 in zip(buf[:l], buf[l:]))

# Display bytes in hex
def tohex(buf):
    return ''.join(("%02x" % (c,)) for c in buf)

# Send one update.
# (Call this periodically.)
def send():
    global server, port, host, password

    # Build request
    nonce = tohex(os.urandom(8))
    req = json.dumps({"host": host, "nonce": nonce})

    # Signature
    s = hashlib.sha256()
    s.update(req + password)
    sig = tohex(fold(fold(s.digest())))

    # Wrapped request
    signed = json.dumps({"req": req, "sig": sig})

    # Send it
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.sendto(signed, (server, port))