chiark / gitweb /
contrib/knock.in: Can now be called from an ordinary shell.
[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 addr, chal = (lambda _, h, p, c: ((h, int(p)), db64(c)))(*argv)
13 sk = S.socket(S.AF_INET, S.SOCK_DGRAM)
14 sk.connect(addr)
15
16 pkt = '\x25' + chal
17 sk.send(pkt)