xref: /freebsd/tests/sys/netpfil/pf/rdr-srcport.py (revision b64c5a0ace59af62eff52bfe110a521dc73c937b)
1#
2# A helper script which accepts TCP connections and writes the remote port
3# number to the stream.
4#
5
6import socket
7
8def main():
9    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
10    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
11    s.bind(('0.0.0.0', 8888))
12    s.listen(5)
13
14    while True:
15        cs, addr = s.accept()
16        cs.sendall(str(addr[1]).encode())
17        cs.close()
18
19if __name__ == '__main__':
20    main()
21