You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.3 KiB

#! /usr/bin/env python3
import socket
import getopt
import sys
from blup.BLP import BLPServer
import blup.BLP
import blup.output
def printUsage(errMsg=None):
if errMsg is not None:
print('error: %s\n' % (errMsg))
print('usage: %s [OPTIONS]' % (sys.argv[0]))
print('supported options:')
print(' -a ADDR address to listen for packets',
'(default: 127.0.0.1)')
print(' --address ADDR\n')
print(' -p PORT port to listen for packets (default: 4242)')
print(' --port PORT\n')
print(' -o OUTPUT where to put the recieved frames',
'(default: shell)')
print(' --output OUTPUT\n')
print(' --eblp use EBLP instead of BLP\n')
print(' --e3blp use E3BLP instead of BLP\n')
print(' -h print this text')
print(' --help')
def main():
try:
(opts, args) = getopt.gnu_getopt(sys.argv, 'ha:p:o:',
['help', 'address=', 'port=',
'output=', 'eblp', 'e3blp'])
opts = dict(opts)
except getopt.GetoptError as e:
printUsage(e.msg)
sys.exit(1)
if '--help' in opts:
printUsage()
sys.exit(0)
if '-a' in opts:
addr = opts['-a']
elif '--address' in opts:
addr = opts['--address']
else:
addr = '127.0.0.1'
if '-p' in opts:
port = opts['-p']
elif '--port' in opts:
port = opts['--port']
else:
port = 4242
if '-o' in opts:
output = opts['-o']
elif '--output' in opts:
output = opts['--output']
else:
output = 'shell'
if '--eblp' in opts:
protocol = blup.BLP.PROTO_EBLP
elif '--e3blp' in opts:
protocol = blup.BLP.PROTO_E3BLP
else:
protocol = blup.BLP.PROTO_BLP
if '--eblp' in opts and '--e3blp' in opts:
printUsage('please only specify one of --eblp or --e3blp')
sys.exit(1)
try:
port = int(port)
except ValueError:
printUsage('invalid port specified')
sys.exit(1)
out = blup.output.getOutput(output)
srv = BLPServer(output=out, addr=addr, port=port, protocol=protocol)
try:
srv.serve()
except KeyboardInterrupt:
pass
if __name__ == '__main__':
main()