diff --git a/server/__pycache__/gns3_helper.cpython-36.pyc b/server/__pycache__/gns3_helper.cpython-36.pyc index 745646374da305b41ff475d36728bc237db394c5..4ba445dd2ed5e0127f25d4d097bb8ce90b2a157c 100644 Binary files a/server/__pycache__/gns3_helper.cpython-36.pyc and b/server/__pycache__/gns3_helper.cpython-36.pyc differ diff --git a/server/client.py b/server/client.py index 3a3f2d5506a42314d33805f9fc0ce6c1584729af..57259ad91b1f2d9023ab0d9be1b4e6f6d1fae565 100644 --- a/server/client.py +++ b/server/client.py @@ -5,7 +5,7 @@ import socket # TCP_IP = '127.0.0.1' # TCP_PORT = 5006 BUFFER_SIZE = 1024 -UDP_IP = "127.0.0.1" +UDP_IP = "10.193.163.46" UDP_PORT = 5005 # MESSAGE = "Hello, World!" diff --git a/server/gns3_helper.py b/server/gns3_helper.py index 2ef94a20c607121f8a2da16e4fbf77187384749f..950d34e789cfe078b9fcf7ac5fdec88016ff5bbc 100644 --- a/server/gns3_helper.py +++ b/server/gns3_helper.py @@ -1,4 +1,7 @@ import gns3 +import getpass +import sys +import telnetlib project_id ='83b40958-ede6-4dec-9cff-e11bdf38bbcc' @@ -10,6 +13,8 @@ def update_nodes_info(): node_info = {} node_info['name'] = node.get('name') node_info['node_id'] = node.get('node_id') + node_info['console'] = node.get('console') + node_info['name'] = node.get('name') if node.get('properties').get('platform'): node_info['platform'] = node.get('properties').get('platform') nodes_info.append(node_info) @@ -26,4 +31,18 @@ def update_links_info(): link_info['node_id_2'] = link.get('nodes')[1].get('node_id') links_info.append(link_info) print('link updated') - return links_info \ No newline at end of file + return links_info + +def telnet_console(PORT, cmd, name): + HOST = "127.0.0.1" + tn = telnetlib.Telnet(HOST, PORT) + + tn.read_very_eager().decode('ascii') + tn.write(cmd.encode('ascii') + b"\r\n") + data = tn.read_until((name+'#').encode()).decode('ascii') + tn.close() + return data + +# print(telnet_console(5000, "show int sum", "R1")) +# print(telnet_console(5000, "show int sum", "R1")) +# print(telnet_console(5000, "show int sum", "R1")) \ No newline at end of file diff --git a/server/index_instruction.txt b/server/index_instruction.txt index f02ed0b82ceabe32a15e7cb1778c7ccea1cf6760..2616d208c2918af9d973f57cdcb839886b760ddb 100644 --- a/server/index_instruction.txt +++ b/server/index_instruction.txt @@ -1,18 +1,19 @@ Provided functionality in GNS3: -0: version information -1: nodes information -2: links information -3: create node -4: delete node -5: create link -6: delete link -7: start all nodes -8: stop all nodes -9: suspend all nodes +00: version information +01: nodes information +02: links information +03: create node +04: delete node +05: create link +06: delete link +07: start all nodes +08: stop all nodes +09: suspend all nodes 10: start one node 11: stop one node 12: suspend one node +13: console command -1: close connection Enter index: \ No newline at end of file diff --git a/server/server.py b/server/server.py index 21081ac37cc14d2e5b6e31d7cfcaaae1736bad1f..97b3d20e0adf48908cf2897ea7f09ff7110f9403 100644 --- a/server/server.py +++ b/server/server.py @@ -10,7 +10,7 @@ import time # TCP_PORT = 5006 BUFFER_SIZE = 1024 # Normally 1024, but we want fast response project_id ='83b40958-ede6-4dec-9cff-e11bdf38bbcc' -UDP_IP = "127.0.0.1" +UDP_IP = "10.193.163.46" UDP_PORT = 5005 sock = socket.socket(socket.AF_INET, # Internet @@ -33,43 +33,44 @@ while 1: msg, addr = sock.recvfrom(BUFFER_SIZE) index = msg.decode('utf-8') - if index == '0': + if index == '00': data = str(gns3.get_version())+str('END') - elif index == '1': + elif index == '01': nodes_info = gn.update_nodes_info() data = str(nodes_info)+str('END') - elif index == '2': + elif index == '02': links_info = gn.update_links_info() data = str(links_info)+str('END') - elif index == '3': + elif index == '03': nodes_info = gn.update_nodes_info() name = len(nodes_info)+1 - # gns3.node_create(project_id, name) - data = str(gns3.node_create(project_id, name))+str('END') - # data = str('OK 4') + gns3.node_create(project_id, name) + data = str('okEND') - elif index == '4': + elif index == '04': nodes_info = gn.update_nodes_info() node_id = nodes_info[-1].get('node_id') data = str(gns3.node_delete(project_id, node_id))+str('END') - elif index == '7': + elif index == '07': data = str(gns3.node_start_all(project_id))+str('END') - elif index == '8': + elif index == '08': data = str(gns3.node_stop_all(project_id))+str('END') - elif index == '9': + elif index == '09': data = str(gns3.node_suspend_all(project_id))+str('END') + elif index[0:2] == '13': + node = nodes_info[0] + data = gn.telnet_console(node.get('console'), index[2:], node.get('name')) + str('END') + elif index == '-1': data = str('close')+str('END') - elif not index: break - else: data = str('incorrect msg')+str('END') sock.sendto(data.encode('utf-8'), addr) # echo diff --git a/server/telnet_console.py b/server/telnet_console.py new file mode 100644 index 0000000000000000000000000000000000000000..b83447c995a3c9774ed3082d1d74756feffdb4f1 --- /dev/null +++ b/server/telnet_console.py @@ -0,0 +1,13 @@ +import getpass +import sys +import telnetlib + +def telnet_console(PORT, cmd): + + HOST = "127.0.0.1" + tn = telnetlib.Telnet(HOST, 5000) + + tn.read_very_eager().decode('ascii') + tn.write(cmd.encode('ascii') + b"\r\n") + data = tn.read_until("R1#".encode()).decode('ascii') + return data