pysap.SAPNI module¶
- class pysap.SAPNI.SAPNI(_pkt, /, *, length=None)[source]¶
Bases:
PacketSAP NI (Network Interface) packet
This packet is used for craft Network Interface packets. It serves only as a container for packets in the different protocols. As this protocol is used by different protocols and the only way to differentiate each one is by the TCP port used, each script using the NI protocol must bind the respective layer with the respective protocol.
For example, a script using the SAP Diag protocol must include the following binds:
bind_layers(SAPNI, SAPDiag, ) bind_layers(SAPNI, SAPDiagDP, ) bind_layers(SAPDiagDP, SAPDiag, ) bind_layers(SAPDiag, SAPDiagItem, ) bind_layers(SAPDiagItem,SAPDiagItem, )
- SAPNI_PING = b'NI_PING\x00'¶
- Cvar:
Constant for keep-alive request messages (NI_PING)
- Type:
C{bytes}
- SAPNI_PONG = b'NI_PONG\x00'¶
- Cvar:
Constant for keep-alive response messages (NI_PONG)
- Type:
C{bytes}
- aliastypes = [<class 'pysap.SAPNI.SAPNI'>, <class 'scapy.packet.Packet'>]¶
- fields_desc: List[AnyField] = [<LenField (SAPNI).length>]¶
- class pysap.SAPNI.SAPNIClient[source]¶
Bases:
objectStub class for a client connecting to the SAP NI server.
- class pysap.SAPNI.SAPNIProxy(bind_address, bind_port, remote_address, remote_port, handler, backlog=5, keep_alive=True, options=None)[source]¶
Bases:
objectSAP NI Proxy
It works by setting a listener
SAPNIStreamSocketand dispatching client’s requests to a given handler class.- Example usage::
proxy = SAPNIProxy(local_host, local_port, remote_host, remote_port, handler_class) proxy.handle_connection()
- class pysap.SAPNI.SAPNIProxyHandler(client, server, options=None)[source]¶
Bases:
objectSAP NI Proxy Handler
Handles NI packets. Works spawning one thread for processing data coming from each pair of client/server.
- process_client(packet)[source]¶
This method is called each time a packet arrives from the client. It must return a packet in the same layer (
SAPNI). Stub method to be overloaded in subclasses.- Parameters:
packet (Packet) – the packet to be processed
- process_server(packet)[source]¶
This method is called each time a packet arrives from the server. It must return a packet in the same layer (
SAPNI). Stub method to be overloaded in subclasses.- Parameters:
packet (Packet) – the packet to be processed
- recv_send(local, remote, process)[source]¶
Receives data from one socket connection, process it and send to the remote connection.
- Parameters:
local (
SAPNIStreamSocket) – the local socketremote (
SAPNIStreamSocket) – the remote socketprocess (function) – the function that process the incoming data
- class pysap.SAPNI.SAPNIServer(server_address, RequestHandlerClass, bind_and_activate=True, socket_cls=None, keep_alive=True, base_cls=None)[source]¶
Bases:
TCPServerBase SAP NI Server class.
Subclasses must define a client class for keeping state information on the connected clients.
- Example usage::
server = SAPNIServer((local_host, local_port), handler_class) server.client_cls = client_class server.serve_forever()
- clients_cls¶
- Cvar:
Client class for storing data about new clients
- Type:
SAPNIClientclass
alias of
SAPNIClient
- get_request()[source]¶
Wrap the socket object with a
SAPNIStreamSocketafter accepting a connection.
- handle_error(request, client_address)[source]¶
Called to handle an error or exception occurred with the server.
- options = None¶
- Ivar:
Options to pass to the request handler
- Type:
object
- class pysap.SAPNI.SAPNIServerHandler(request, client_address, server)[source]¶
Bases:
BaseRequestHandlerSAP NI Server Handler
Handles
SAPNIpackets coming from aSAPNIServer.- close()[source]¶
Close a client connection and deletes the client from the state information on the server.
- handle()[source]¶
Handle a client connection. The handler assumes the client connection is a
SAPNIStreamSocketobject. After received aSAPNIpacket, it stores it on the ‘packet’ instance variable and pass the control to the handle_data method.
- class pysap.SAPNI.SAPNIServerThreaded(server_address, RequestHandlerClass, bind_and_activate=True, socket_cls=None, keep_alive=True, base_cls=None)[source]¶
Bases:
ThreadingMixIn,SAPNIServerA SAP NI Server implementation using threading
- class pysap.SAPNI.SAPNIStreamSocket(sock, keep_alive=True, base_cls=None)[source]¶
Bases:
StreamSocketStream socket implementation of the SAP Network Interface (NI) layer.
- desc = 'NI Stream socket'¶
- classmethod get_nisocket(host, port, **kwargs)[source]¶
Helper function to obtain a
SAPNIStreamSocket.- Parameters:
host (C{string}) – host to connect to
port (
int) – port to connect tokwargs – arguments to pass to
SAPNIStreamSocketconstructor
- Returns:
connected socket
- Return type:
- Raises:
socket.error – if the connection to the target host/port failed
- recv()[source]¶
Receive a packet at the NI layer, first reading the length field and the reading the data. If the stream is waiting for a new packet and the remote peer sends a keep-alive request (
NI_PING), the receive method will respond with a keep-alive response (NI_PONG) to keep the communication stable.