Commit f906e304 authored by aoh's avatar aoh
Browse files

Replace DNS updater with icanhazip-style

Signed-off-by: aoh's avataraoh <>
parent f60fc811
#!/usr/bin/env python3
import socket
import socketserver
import argparse
import ssl
import ip_query_pb2
class RequestHandler(socketserver.BaseRequestHandler):
def handle(self):
resp = ip_query_pb2.Query()
resp.address = self.client_address[0]
class ForkingServer(socketserver.ForkingMixIn, socketserver.TCPServer):
def __init__(self, address, handler, family):
self.address_family = family
super().__init__(address, handler)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='LysNS IP update server.')
parser.add_argument('host', type=str, help='The listening address of the server.')
parser.add_argument('port', type=int, help='The listening port of the server.')
parser.add_argument('cert', type=str, help='The SSL certificate of the server.')
parser.add_argument('key', type=str, help='The private key for the SSL certificate.')
parser.add_argument('--ipv6', action='store_true', help='The given listening address is IPv6.')
args = parser.parse_args()
family = socket.AF_INET
if args.ipv6:
family = socket.AF_INET6
server = ForkingServer((, args.port), RequestHandler, family)
server.socket = ssl.wrap_socket(server.socket,
server_side = True,
certfile = args.cert,
keyfile = args.key)
......@@ -3,26 +3,18 @@ import argparse
import os
import socket
import ssl
from urllib import request
import ip_query_pb2
def request_address(address, port, cert):
def request_address(ipv6=False):
This function obtains the external ip address of the current machine.
msg = ip_query_pb2.Query()
connection = ssl.wrap_socket(socket.create_connection((address, port,)),
cert_reqs=ssl.CERT_REQUIRED, ca_certs=cert)
buf = connection.recv(MAX_MSG_LEN)
answer = ip_query_pb2.Query()
if ipv6:
address = "Error" # TODO ipv6
address = request.urlopen("").read() # TODO replace with
return answer.address
return address
def nsupdate(domain_server, domain, ip):
res = os.system('''nsupdate -k key.key -p 2223 <<EOF
......@@ -35,16 +27,13 @@ def nsupdate(domain_server, domain, ip):
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='LysNS IP update client.')
parser.add_argument('server', type=str, help='Server address.')
parser.add_argument('port', type=int, help='Server port.')
parser.add_argument('cert', type=str, help='Public certificate for the server.')
parser.add_argument('domain_server', type=str, help='The address of the DNS server you wish to update.')
parser.add_argument('domain', type=str, help='The domain record you wish to update.')
parser.add_argument('--ipv6', action='store_true', help='Perform an IPv6 update.')
args = parser.parse_args()
address = request_address(args.server, args.port, args.cert)
address = request_address(args.ipv6)
print('Got {} from the server.'.format(address))
print('Got {}'.format(address))
nsupdate(args.domain_server, args.domain, address)
all: ip-query.proto
protoc --python_out=. ip-query.proto
syntax = "proto2";
package lysns;
message Query {
optional string address = 1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment