From owner-freebsd-stable Tue Oct 23 12:25:47 2001 Delivered-To: freebsd-stable@freebsd.org Received: from lurza.secnetix.de (lurza.secnetix.de [212.66.1.130]) by hub.freebsd.org (Postfix) with ESMTP id C916B37B409 for ; Tue, 23 Oct 2001 12:25:43 -0700 (PDT) Received: (from olli@localhost) by lurza.secnetix.de (8.11.6/8.11.6) id f9NJPfM96628; Tue, 23 Oct 2001 21:25:41 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Date: Tue, 23 Oct 2001 21:25:41 +0200 (CEST) Message-Id: <200110231925.f9NJPfM96628@lurza.secnetix.de> From: Oliver Fromme To: freebsd-stable@FreeBSD.ORG Reply-To: freebsd-stable@FreeBSD.ORG Subject: Re: Knowing how many computers are connected to your server? In-Reply-To: X-Newsgroups: list.freebsd-stable User-Agent: tin/1.5.4-20000523 ("1959") (UNIX) (FreeBSD/4.4-RELEASE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Noor Dawod 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