I have an app that makes some kind of upd ping to the network and for some short time listens for some port in order to receive some feedback during some timeout. It is short enough to observe if with netstat. I need events of opening port and closing it to be logged. Any ideas?
1 Answer
I'm not sure it is the best approach but i used
buffer1=$(ss -ltun); while true; do buffer2=$(ss -ltun); diff <(echo "$buffer1") <(echo "$buffer2") >> netlog2.log; buffer1=$buffer2; done
^C
cat netlog2.log
6c6
< tcp 0 8 172.16.1.215:31087 :
---
tcp 0 8 172.16.1.215:47339 :
6d5 < tcp 0 8 172.16.1.215:47339 :
11a11 tcp 0 8 172.16.1.215:49491 :
11d10 < tcp 0 8 172.16.1.215:49491 :
10a11 tcp 0 8 172.16.1.215:35249 :
strace
with the some filtering to get only open and close system calls.