chiark / gitweb /
Merge branches 'mdw/knock' and 'mdw/ipv6' into bleeding
[tripe] / contrib / greet.in
1 #! @PYTHON@
2 ### greet HOST PORT CHALLENGE
3 ### Sends a TrIPE greeting packet to the server listening on HOST and PORT.
4 ### The payload is the base64-encoded CHALLENGE.
5
6 import socket as S
7 from sys import argv
8
9 def db64(s):
10   return (s + '='*((-len(s))%4)).decode('base64')
11
12 ai, chal = (lambda _, h, p, c:
13             (S.getaddrinfo(h, p, S.AF_UNSPEC, S.SOCK_DGRAM, S.IPPROTO_UDP,
14                              S.AI_NUMERICHOST | S.AI_NUMERICSERV)[0],
15              db64(c)))(*argv)
16 sk = S.socket(ai[0], S.SOCK_DGRAM)
17 sk.connect(ai[4])
18
19 pkt = '\x25' + chal
20 sk.send(pkt)