Library tn3270

TN3270 Emulator Library

Summary

  • This library implements an RFC 1576 and 2355 (somewhat) compliant TN3270 emulator.

The library consists of one class Telnet consisting of multiple functions required for initiating a TN3270 connection.

The following sample code illustrates how scripts can use this class to interface with a mainframe:

mainframe = Telnet:new()
status, err = mainframe:initiate(host, port)
status, err = mainframe:send_cursor("LOGON APPLID(TSO)")
mainframe:get_data()
curr_screen = mainframe:get_screen()
status, err = mainframe:disconnect()

The implementation is based on packet dumps, x3270, the excellent decoding provided by Wireshark and the Data Stream Programmers Reference (Dec 88)

Source: https://svn.nmap.org/nmap/nselib/tn3270.lua

Functions

any_hidden (self)

Any Hidden Fields

connect (self, host, port)

Connects to a tn3270 servers

DECODE_BADDR (byte1, byte2)

Decode Buffer Address

disableSSL (self)

Disable SSL by default the tn3270 object uses SSL first. This disables SSL

ENCODE_BADDR (self, address, integer)

Encode Buffer Address

get_data (self)

rebuilds tn3270 screen based on information sent Closes the socket if the mainframe has closed the socket on us Is done reading when it encounters EOR

hidden_fields_location (self)

Hidden Fields

in3270 (self)

Check to see if we're in TN3270

initiate (self, host, port)

Initiates tn3270 connection

negotiate_tn3270 (self)

Function to negotiate TN3270 sub options

new (self, socket)

Creates a new TN3270 Client object

process_data (self)

Also known as process_eor

process_write (self, data, tn3270)

WCC / tn3270 data stream processor

send_cursor (self, data, string)

Sends data at the current cursor location. Ignores field attributes.

send_location (self, location, data)

Sends the data to the location specified

send_locations (self, location_tuple)

Sends the data to multiple locations on the screen

send_tn3270 (self, data)

Sends TN3270 Packet

store3270 (self, char)

Stores a character on a buffer to be processed

ts_processor (self, data)

Telnet State processor

Functions

any_hidden (self)

Any Hidden Fields

Parameters

self
 
connect (self, host, port)

Connects to a tn3270 servers

Parameters

self
 
host
 
port
 
DECODE_BADDR (byte1, byte2)

Decode Buffer Address

Buffer addresses can come in 14 or 12 (this terminal doesn't support 16 bit) this function takes two bytes (buffer addresses are two bytes long) and returns the decoded buffer address.

Parameters

byte1
 
byte2
 

Return value:

integer of buffer address
disableSSL (self)

Disable SSL by default the tn3270 object uses SSL first. This disables SSL

Parameters

self
 
ENCODE_BADDR (self, address, integer)

Encode Buffer Address

Parameters

self
 
address
 
integer
buffer address

Return value:

TN3270 encoded buffer address (12 bit) as string
get_data (self)

rebuilds tn3270 screen based on information sent Closes the socket if the mainframe has closed the socket on us Is done reading when it encounters EOR

Parameters

self
 
hidden_fields_location (self)

Hidden Fields

Parameters

self
 
in3270 (self)

Check to see if we're in TN3270

Parameters

self
 
initiate (self, host, port)

Initiates tn3270 connection

Parameters

self
 
host
 
port
 
negotiate_tn3270 (self)

Function to negotiate TN3270 sub options

Parameters

self
 
new (self, socket)

Creates a new TN3270 Client object

Parameters

self
 
socket
 
process_data (self)

Also known as process_eor

Parameters

self
 
process_write (self, data, tn3270)

WCC / tn3270 data stream processor

Parameters

self
 
data
 
tn3270
data stream

Return values:

  1. status true on success, false on failure
  2. changes self.buffer to match requested changes
send_cursor (self, data, string)

Sends data at the current cursor location. Ignores field attributes.

It only uses enter key (AID = 0x7d) to send this data for more complicated items use send_location

Parameters

self
 
data
 
string
you wish to send.
send_location (self, location, data)

Sends the data to the location specified

Using a location on the screen sends the data

Parameters

self
 
location
 
data
 
send_locations (self, location_tuple)

Sends the data to multiple locations on the screen

Using a supplied tuple of location and data generates tn3270 data to fill out the screen

Parameters

self
 
location_tuple
 
send_tn3270 (self, data)

Sends TN3270 Packet

Expands IAC to IAC IAC and finally appends IAC EOR

Parameters

self
 
data
 
store3270 (self, char)

Stores a character on a buffer to be processed

Parameters

self
 
char
 
ts_processor (self, data)

Telnet State processor

Parameters

self
 
data
 

Return value:

true if success false if encoutered any issues