Using netcat to Provide a Network Endpoint During Development

Written by James McDonald

April 2, 2012

I’m in the process of creating a Perl script that sends configuration commands to a SATO printer via a Moxa networked serial port.

My problem with the development process is the Moxa and SATO Printer is in a Tin Shed that climbs to 35° C plus. It’s not much fun sitting with a laptop in sweltering heat.

So noodling away at home I’ve found a great workaround which is to use netcat to emulate the Moxa networked serial port. Using netcat I can send all the data to a host and port of my choosing and get it all functioning as it should before finally retargetting it to point to the Moxa networked serial port.

Following is the ncat command to run on Linux/Cygwin host and a sample Perl script that might when I’m finished become part of a web accessible CGI script to control the printer.

ncat -l 2000 -k

#!/usr/bin/perl -w

use Net::Telnet;
use strict;

my $obj = sato->new();

$obj->{barcode} = '12345678901234';
$obj->{description} = "A TEST DESCRIPTION";


package sato;

sub send_print {
	my $self = shift;
	my $t = Net::Telnet->new( Timeout => 10,
						Port => 2000 


	my $esc = "\e"; # escape command

	$t->put("Before " . $esc . "H0800 $self->{barcode} $self->{description} put from script\n"); # no field sep \n6

sub new {
	my $class = shift;
	my $self  = bless { @_ }, $class;
	return $self;

sub __set_properties {
		my $self = shift;
		$self->{label_width} = "100";
		$self->{label_height} = "50";
		$self->{font} = "XL1";
		$self->{barcode} = '01234567891234' unless $self->{barcode};
		$self->{description} = 'A TWENTY FOUR CHAR DESC4' unless $self->{description};

1 Comment

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Network speed test host to host

On Ubuntu / Debian apt-get install iperf3 On Windows download it from Make...

Clear HSTS Settings in CHrome

Open chrome://net-internals/#hsts enter the domain in the query field and click Query to confirm it has HSTS settings...