def write(self, agent_packet, sock, msgResponse):

        packet_writer = PacketWriter()
        b_msg = packet_writer.parse_to_bytes(msgResponse)

        agent_packet.send(sock, b_msg)

        print('[RSP]', msgResponse)
Exemple #2
0
def login(sock, sessionId, requestId, handlers):

    r_msg = handlers['login']()
    print("[REQ]", r_msg)

    packet_writer = PacketWriter()
    b_msg = packet_writer.parse_to_bytes(r_msg)

    client_packet = DofClientPacket()
    client_packet.set_session_id(sessionId)
    client_packet.set_request_id(requestId)
    client_packet.send(sock, b_msg)

    r_msg = recvData(sock, sessionId, requestId)

    return r_msg.get_int("session_id")
Exemple #3
0
def sendThread(sock, handlers):

    print('\n[CLIENT] Start')
    print('\n help: command list')
    print('\n exit: process quit')

    requestId = 0
    sessionId = 0

    sessionId = login(sock, sessionId, requestId, handlers)

    while True:

        sys.stdout.write('>> ')
        sys.stdout.flush()

        msgName = sys.stdin.readline()
        try:

            msgName = msgName.rstrip()

            if msgName == '':
                continue

            if msgName == 'exit':
                break

            if msgName == 'help':
                print('## command list ##')
                print('exit')
                print('help')
                for key in handlers:
                    print(key)
                continue

            try:
                handler = handlers[msgName]
            except Exception:
                print('\n[CLIENT] Not support handler - ' + msgName)
                continue

            r_msg = handler()  #.request()

            requestId += 1
            print("[REQ]", r_msg)

            packet_writer = PacketWriter()
            b_msg = packet_writer.parse_to_bytes(r_msg)

            client_packet = DofClientPacket()
            client_packet.set_session_id(sessionId)
            client_packet.set_request_id(requestId)
            client_packet.send(sock, b_msg)

            r_msg = recvData(sock, sessionId, requestId)

            if r_msg.get_name() == 'LOGIN':
                sessionId = r_msg.get_int("session_id")

        except Exception:
            traceback.print_exc(file=sys.stdout)
            break

    sock.close()
Exemple #4
0
from insoft.openmanager.message.packet import Packet
from insoft.openmanager.message.packet_reader import PacketReader
from insoft.openmanager.message.packet_writer import PacketWriter
from insoft.openmanager.message.client_packet_dof import DofClientPacket

msg = Message("LOGIN")
msg.set_str('user_id', 'root')
msg.set_str('user_pw', 'changeit')
msg.set_int('client_type', 6)

print(msg)

addr = ('192.168.9.62', 9100)
s = socket.socket()
s.connect(addr)

packet_writer = PacketWriter()
b_msg = packet_writer.parse_to_bytes(msg)

client_packet = DofClientPacket()
client_packet.send(s, b_msg)

print("send message...")

time.sleep(3)

r_msg = client_packet.recv(s)
print(r_msg)

time.sleep(3)
Exemple #5
0
import socket

from insoft.openmanager.message.agent_packet import AgentPacket
from insoft.openmanager.message.message import Message
from insoft.openmanager.message.packet import Packet
from insoft.openmanager.message.packet_writer import PacketWriter

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_addr = ("192.168.255.79", 10000)

sock.bind(server_addr)
sock.listen()

while True:
    print("Waiting client...")
    connection, client_addr = sock.accept()
    try:
        print("Connected.. ", client_addr)

        packet = AgentPacket()
        msg = packet.recv(connection)
        print("[REQ]")
        print(msg)

        send_data = PacketWriter().parse_to_bytes(msg)
        packet.send(connection, send_data)

    except Exception as e:
        print(e)