Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Oct 2001 21:25:41 +0200 (CEST)
From:      Oliver Fromme <olli@secnetix.de>
To:        freebsd-stable@FreeBSD.ORG
Subject:   Re: Knowing how many computers are connected to your server?
Message-ID:  <200110231925.f9NJPfM96628@lurza.secnetix.de>
In-Reply-To: <PHEBIOJOBJJLIIJCOINKKEIOEFAA.noor@comrax.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Noor Dawod <noor@comrax.com> wrote:
 > In FreeBSD, how can I list how many computers (as opposed to connections
 > that can be many from one computer) are connected to a specific network
 > address or port or IP?

In general, that's not possible.  You can list connections
by remote IP (see netstat(1) and sockstat(1)), but remember
that two different remote IPs may actually belong to the
same computer, and two connections from the same IP might
belong to different computers (for example, when the other
side uses NAT or port-based switching).

If you're satisfied with knowing how many different IP
addresses have connections open to your machine, the
following will do (broken up for readability):

   netstat -an \
   | sed -n 's/.* \([0-9.]*\)\.[0-9]* *ESTABLISHED/\1/p' \
   | sort -u \
   | wc -l

And if you want the actual number of connections per IP
listed, use this:

   netstat -an \
   | sed -n 's/.* \([0-9.]*\)\.[0-9]* *ESTABLISHED/\1/p' \
   | sort \
   | uniq -c

If you have multiple interfaces (or multiple local IPs),
you can refine the sed expression to list by local IP.
This is left as an exercise to the reader.  ;-)

Regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"All that we see or seem is just a dream within a dream" (E. A. Poe)

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200110231925.f9NJPfM96628>