diff options
author | 2016-08-18 15:24:21 +0300 | |
---|---|---|
committer | 2016-08-18 16:26:09 +0300 | |
commit | b64ee3961384a4b0ddb9613a5940c58a517de30d (patch) | |
tree | 3fd60c06bbe8c8067f94063e0849f465919a21fd /scripts/automation/trex_control_plane/examples | |
parent | a08d3b9ba1c5010827029bab030ef61d73368fa3 (diff) | |
parent | 6796bb99573f15c77a007434feabb30291ac1670 (diff) |
Merge branch 'scapy_server'
Diffstat (limited to 'scripts/automation/trex_control_plane/examples')
-rwxr-xr-x | scripts/automation/trex_control_plane/examples/zmq_server_client.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/examples/zmq_server_client.py b/scripts/automation/trex_control_plane/examples/zmq_server_client.py new file mode 100755 index 00000000..15f37f1a --- /dev/null +++ b/scripts/automation/trex_control_plane/examples/zmq_server_client.py @@ -0,0 +1,45 @@ +import sys
+import os
+python2_zmq_path = os.path.abspath(os.path.join(os.pardir,os.pardir,os.pardir,
+ 'external_libs','pyzmq-14.5.0','python2','fedora18','64bit'))
+sys.path.append(python2_zmq_path)
+import zmq
+import json
+from argparse import *
+
+parser = ArgumentParser(description=' Runs a Scapy Server Client example ')
+parser.add_argument('-p','--dest-scapy-port',type=int, default = 4507, dest='dest_scapy_port',
+ help='Select port to which this Scapy Server client will send to.\n default is 4507\n',action='store')
+parser.add_argument('-s','--server',type=str, default = 'localhost', dest='dest_scapy_ip',
+ help='Remote server IP address .\n default is localhost\n',action='store')
+
+args = parser.parse_args()
+
+dest_scapy_port = args.dest_scapy_port
+dest_scapy_ip = args.dest_scapy_ip
+
+context = zmq.Context()
+
+# Socket to talk to server
+print 'Connecting:'
+socket = context.socket(zmq.REQ)
+socket.connect("tcp://"+str(dest_scapy_ip)+":"+str(dest_scapy_port))
+try:
+ while True:
+ command = raw_input("enter RPC command [enter quit to exit]:\n")
+ if (command == 'quit'):
+ break
+ user_parameter = raw_input("input for command [should be left blank if not needed]:\n")
+ json_rpc_req = { "jsonrpc":"2.0","method": command ,"params":[user_parameter], "id":"1"}
+ request = json.dumps(json_rpc_req)
+ print("Sending request in json format %s" % request)
+ socket.send(request)
+
+ # Get the reply.
+ message = socket.recv()
+ print("Received reply %s [ %s ]" % (request, message))
+except KeyboardInterrupt:
+ print('Terminated By Ctrl+C')
+ socket.close()
+ context.destroy()
+
|