Created
December 21, 2020 19:28
-
-
Save ramiroencinas/6b83f02df3bd4459a0c0d62e319c9ba2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use POSIX qw(strftime); | |
my $date, $remote_ip, $remote_port, $user, $group, $cmdpath; | |
while (1) { | |
foreach (`ss -tupn`) { | |
$date = strftime "%d-%m-%Y %H:%M:%S", localtime; | |
if ($_ =~ /(\d+\.\d+\.\d+\.\d+):(\d+)\s+users.*?pid=(\d+)/) { | |
$remote_ip = $1; | |
$remote_port = $2; | |
$user = `stat --printf="%U" /proc/$3/exe`; | |
$group = `stat --printf="%G" /proc/$3/exe`; | |
$cmdpath = `stat --printf="%N" /proc/$3/exe`; | |
$cmdpath =~ s/^.*?-> '//; | |
$cmdpath =~ s/'//; | |
print "$date $user $group $cmdpath $remote_ip $remote_port\n"; | |
} | |
} | |
sleep 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment