giovedì 9 maggio 2013

How To Identify If a Port Is Listening on a Unix Server



Hi all

To see if a port is listening on a Unix Server command is :

           netstat -an | grep port number | grep LISTEN

To see what process is using a port the command is :

           lsof -i tcp:port number

Here a simple perl programm to open a port and check a connection from a client web :


#!/usr/bin/perl -w
        use IO::Socket;
        use Net::hostent;              # for OO version of gethostbyaddr
        $PORT = 8080;

        $server = IO::Socket::INET->new( Proto     => 'tcp',
                                         LocalPort => $PORT,
                                         Listen    => 5,
                                         Reuse     => 1) or die "can't setup server" unless $server;

    printf("\nSERVER Waiting for client connection on port $PORT");

         while ($client = $server->accept()) {

          printf("\nClient Connected\n");

          $client->autoflush(1);
          print $client " Connected You are connected on port $PORT";

          close $client;
        }

Stay tuned


Nessun commento:

Posta un commento

Check Mid Year Objectives

Hi all Today middle year check of my 2026's goals. 1. ENGLISH Improve listening comprehension (So and So)   See at least one or two film...