• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 545
  • Last Modified:

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

Hi,

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?


0
frustrated16
Asked:
frustrated16
  • 4
  • 2
  • 2
  • +2
1 Solution
 
PsiCopCommented:
Ports are not "setup". Ports exist as part of the TCP/IP protocol suite.
0
 
PsiCopCommented:
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
0
 
gripeCommented:
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:

#!/usr/bin/perl

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.



0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
gripeCommented:
Sorry, that should read 'logs the incoming user's IP address to syslog'
0
 
ahoffmannCommented:
sh -c "while [ 1 ]; do netcat -p 4242 -l >> file; done"
0
 
chris_calabreseCommented:
If you just want to log the incoming IP address, you can do this trivially with TCP Wrappers.

http://ftp.porcupine.org/pub/security/
0
 
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....
0
 
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
0
 
gripeCommented:
Frustrated:

See ahoffman's (awesome) answer above. It's a shell script. You might need to install netcat.
0
 
gripeCommented:
Could someone please give these points to ahoffman? His answer was perfect.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now