How to setup a new port - listen and log all incoming on that port


I would like to setup a new port on my solaris workstation (ultra 10 running solaris 9)
Once the port is setup - I would simply like to log all incoming data to that port to a standard unix log file

Can this be done - if so - is there a lot involved?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ports are not "setup". Ports exist as part of the TCP/IP protocol suite.
To enable the functionality you desire, I would use the included SysLog daemon (syslogd). Its function is to record events into a log file, and it can be configured to accept event information from other hosts over a TCP/IP link.

See --> man syslogd

See --> man syslog

See --> man syslogd.conf
You'd need to write a program that listens on the port and provides the logging functionality. It's (somewhat) trivial to do this in Perl. Here's an example program that logs the incoming user's port number to syslog:


use warnings;
use strict;
use Socket;
use Sys::Syslog;

my $port = '8000';
my $protocol = getprotobyname('tcp');

socket(SERVER, PF_INET, SOCK_STREAM, $protocol) or die "Couldn't create socket: $!";
setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1) or die "Couldn't set socket options: $!";

my $paddr = sockaddr_in($port, INADDR_ANY);

bind(SERVER, $paddr) or die "Couldn't bind to port: $port: $!";
listen(SERVER, SOMAXCONN) or die "Couldn't establish listen: $!";

while (my $client = accept(CLIENT, SERVER)) {
        my ($port, $ip) = sockaddr_in($client);
        my $ipaddress = inet_ntoa($ip);
        syslog 'CRIT', "Client connect from: %s", $ipaddress;
        print CLIENT "Disconnect.\n";
        close CLIENT;

It wouldn't be too hard to modify this to dump incoming data to a log file or whatever else you want to do.

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Sorry, that should read 'logs the incoming user's IP address to syslog'
sh -c "while [ 1 ]; do netcat -p 4242 -l >> file; done"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If you just want to log the incoming IP address, you can do this trivially with TCP Wrappers.
frustrated16Author Commented:
Any way I can do this outside of perl?     a shell script for instance?

I do want to just log the incoming ip address.... I want to log the data they are sending....
frustrated16Author Commented:
Sorry - I meant to say...

I 'dont' want to just log the incoming ip address... .I want to log the data they are sending also

See ahoffman's (awesome) answer above. It's a shell script. You might need to install netcat.
Could someone please give these points to ahoffman? His answer was perfect.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.