Get current active network connections on a Linux host using golang

Hi,

I was wondering if someone’s come across any existing package/s that are able to get a list of current active network connections on a host (Linux) and put those into a array of maps (I guess) or something like it?

The idea is to check in a configurable interval for current connections (incoming and outgoing) and log the IPs ideally trying to get the name, but IP will be a good start.

Any links / ideas ? Maybe there’s something in the standard lib that can do this?

Thanks!
Alex

This is possible easily by interfacing with conntrack.

A quick google comes up with https://github.com/typetypetype/conntrack as an example.

If your wanting realtime on-the-wire connection tracking without the overhead of using conntrack you could build a simple tcp state machine on top of gopacket and capture the interface(s) using pcap/afpacket.

1 Like

cool thanks! maybe i didn’t get far with google as I was thinking along the lines of netstat command, which thinking about it now, should also be available as a file somewhere (or many) in /proc - I’ll have a go at the above too - thanks a lot! alex

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.