Skip to content

Instantly share code, notes, and snippets.

@Twisol
Created September 29, 2010 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Twisol/602242 to your computer and use it in GitHub Desktop.
Save Twisol/602242 to your computer and use it in GitHub Desktop.
%%{
machine telnet_nvt_common;
alphtype unsigned char;
# Special bytes that must be handled differently from normal text:
CR = "\r"; # Only \0 or \n may follow
IAC = 255; # Telnet command marker
special_byte = CR | IAC;
# The only bytes that may follow a CR:
NL = "\n";
NUL = "\0";
# The only bytes that may follow an IAC:
SE = 240;
NOP = 241;
DM = 242;
BRK = 243;
IP = 244;
AO = 245;
AYT = 246;
EC = 247;
EL = 248;
GA = 249;
SB = 250;
WILL = 251;
WONT = 252;
DO = 253;
DONT = 254;
# Sorting the above IAC commands by type:
basic_command_type = NOP | BRK | IP | AO | AYT | EC | EL | GA;
arg_command_type = WILL | WONT | DO | DONT;
subneg_command_type = SB;
###
# Plain text
###
plain_text = (^special_byte | IAC IAC) @text;
###
# CR sequence
###
cr_sequence = CR ( NUL @cr
| NL @newline
| ^(NUL|NL) @{fhold;} @warning_cr @cr
);
###
# IAC sequence
###
# IAC commands
basic_command = IAC basic_command_type @command_mark @basic_command;
arg_command = IAC arg_command_type @command_mark
any @option_command;
subneg_command = IAC subneg_command_type
any @subneg_command
(cr_sequence|plain_text)*
IAC SE @subneg_command_end;
iac_sequence = ( basic_command
| arg_command
| subneg_command
);
###
# Telnet stream
###
# These are the three basic data formats that will be accepted
# by the telnet parser.
telnet_stream = ( iac_sequence
| cr_sequence
| plain_text
)*;
main := telnet_stream;
}%%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment