Skip to content

Instantly share code, notes, and snippets.

@mpapierski
Created December 20, 2018 16:31
Show Gist options
  • Save mpapierski/52696a45e96c5efc3fe85db94bf4cf9f to your computer and use it in GitHub Desktop.
Save mpapierski/52696a45e96c5efc3fe85db94bf4cf9f to your computer and use it in GitHub Desktop.
fake babeld
#!/usr/bin/env python
import socket
import threading
TCP_IP = '::1'
TCP_PORT = 6872
BUFFER_SIZE = 20
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)
def handle_client(conn):
conn.send('ALTHEA 0.1\nok\n')
print('Thread started for', conn)
buf = ''
while 1:
data = conn.recv(BUFFER_SIZE)
if not data: break
buf += data
idx = buf.find('\n')
while idx != -1:
line = buf[:idx]
buf = buf[idx + 1:]
print('rx {}'.format(line))
if line == 'dump':
conn.send('''local fee 500000
metric factor 1900
add interface lo up false
add xroute fd00::1337:e6f/128-::/0 prefix fd00::1337:e6f/128 from ::/0 metric 0
ok
''')
else:
conn.send('ok\r\n')
idx = buf.find('\n')
print('Done')
conn.close()
while True:
print('Accepting...')
conn, addr = s.accept()
print 'Connection address:', addr
th = threading.Thread(target=handle_client, args=(conn,))
th.setDaemon(True)
th.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment