Is there an interface to get the currently connected IPs and their state in Linux? I am aware of ss
and netstat
, but I want to use /proc/
or some other "official" kernel interface that already has them (if it exists). If it doesn't exist where would I start to get this information? Basically, I need an interface that has this information so I can retrieve it programmatically.
Linux interface to get connected IPs
linuxnetworking
Best Answer
Besides
ss
andnetstat
I currently don't know any other tools that I'd recommend.For how to get this information:
If you
man netstat
, you can see at the sectionFILES
some listed files that netstat uses to collect its information.Among these, there are
/proc/net/tcp
and/proc/net/udp
.If you
cat /proc/net/tcp
you can see various information about tcp connections on your system.A sample output would be
rem_address
here is the IP you are looking for. I don't know much about it, but I thinkst
gives you information about the current state.0A
should meanLISTEN
,01
meansESTABLISHED
.Decoding a
local_address
orrem_address
is rather easy,8700A8C0:8F76
for example:More information about the
/proc/net
directory is here.More information about the presented data is here.
A related SO thread is also here.