47 lines
1.3 KiB
Python
Executable File
47 lines
1.3 KiB
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import sys
|
|
import getopt
|
|
from lmwsip import LmwSip
|
|
|
|
def usage():
|
|
print("siprun [-s] [-h <host>] [-p <port>] [<files>]")
|
|
print("\t-s: SSL connection")
|
|
print("\t-h <host>: Connect to host")
|
|
print("\t-p <port>: Connect to port")
|
|
print("\t-<files>: LMW commando files")
|
|
|
|
def main():
|
|
try:
|
|
opts, args = getopt.getopt(sys.argv[1:], "sh:p:", ["help", "output="])
|
|
except getopt.GetoptError as err:
|
|
# print help information and exit:
|
|
print(err) # will print something like "option -a not recognized"
|
|
usage()
|
|
sys.exit(2)
|
|
ssl=False
|
|
host=None
|
|
port=None
|
|
for o, a in opts:
|
|
if o == "-s":
|
|
ssl=True
|
|
elif o == "-h":
|
|
host=a
|
|
elif o == "-p":
|
|
port=a
|
|
if (host==None or port==None):
|
|
print("Set host and port")
|
|
usage()
|
|
sys.exit(3)
|
|
lmwsip = LmwSip(ssl=ssl, host=host, port=port)
|
|
for cmdfile in args:
|
|
with open(cmdfile, "r") as f:
|
|
for cmd in f:
|
|
print("> [%s]" % (cmd.strip('\n')))
|
|
lmwsip.send(cmd.replace('\n', '\r'))
|
|
print("< [%s]" % (lmwsip.recv().decode('utf-8').strip('\r')))
|
|
f.close()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|