#!/usr/sbin/dtrace -s #pragma D option quiet /* * Count the number of inbound TCP connections by remote host and local port. * This script will print the remote's hostname if it can. */ dtrace:::BEGIN { printf("Tracing... Hit Ctrl-C to end.\n"); } tcp:::accept-established { @num[args[2]->ip_saddr, args[4]->tcp_dport] = count(); } dtrace:::END { printf(" %-26s %-8s %8s\n", "HOST", "PORT", "COUNT"); printa(" %-26I %-8P %@8d\n", @num); }