Refreshing netstat output with Perl


Article from Issue 89/2008

The netstat utility reveals how your Linux box interacts with the local network. With a few Perl modules, you can develop a tool that displays the data dynamically, exactly the way top does.

When you want to know which ports are currently being used, you call netstat. This practical Linux utility can be run in several modes, which the user controls through command-line options. For example, the -s option produces network traffic statistics, and -put displays the ports of all applications that are currently communicating over TCP. Both outputs are useful, but what is really interesting is the chronological progression of events rather than a snapshot at a given moment.

The top utility serves as a model for this kind of dynamic output, displaying and continually updating the CPU load, memory usage, and other basic data of currently running processes. Thanks to CPAN, creating a dynamic terminal application like this from the static output from top is not really difficult.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • System Diagnosis Tools

    To check on the health of a Linux system, administrators can turn to vmstat, iostat, netstat, and ifstat. Or, you can just use the versatile dstat, which combines the features of several tools in a single package.

  • Charly's Column

    Without Network Address Translation (NAT) on many LANs, the IPv4 Internet address space would have been exhausted years ago. Still, it’s probably a good idea to check what comes through your NAT connections.

  • Perl: Lyrical Logfiles

    Instead of just monitoring incoming requests in your web server's logfile, a sound server makes them audible and lets you listen to the tune of users surfing the site.

  • Command Line: Network Diagnostic Tools

    Linux has the right tools to track down network errors and open the way for data packets.

  • lsof

    In Linux, everything is a file – directories, devices, pipes – so lsof (list open files) reveals what's happening on your system.

comments powered by Disqus