Das CPAN-Modul Win32::IPHelper bietet Zugriff auf GetExtendedTcpTable
, die die ProcessID
für jede Verbindung bereitstellt.
Win32::Process::Info gibt Informationen über alle laufenden Prozesse.
die Kombination der beiden, erhalten wir:
#!/usr/bin/perl
use strict;
use warnings;
use Win32;
use Win32::API;
use Win32::IPHelper;
use Win32::Process::Info qw(NT);
use Data::Dumper;
my @tcptable;
Win32::IPHelper::GetExtendedTcpTable(\@tcptable, 1);
my $pi = Win32::Process::Info->new;
my %pinfo = map {$_->{ProcessId} => $_ } $pi->GetProcInfo;
for my $conn (@tcptable) {
my $pid = $conn->{ProcessId};
$conn->{ProcessName} = $pinfo{$pid}->{Name};
$conn->{ProcessExecutablePath} = $pinfo{$pid}->{ExecutablePath};
}
@tcptable =
sort { $a->[0] cmp $b->[0] }
map {[ sprintf("%s:%s", $_->{LocalAddr}, $_->{LocalPort}) => $_ ]}
@tcptable;
print Dumper \@tcptable;
Ausgang:
[
'0.0.0.0:135',
{
'RemotePort' => 0,
'LocalPort' => 135,
'LocalAddr' => '0.0.0.0',
'State' => 'LISTENING',
'ProcessId' => 1836,
'ProcessName' => 'svchost.exe',
'ProcessExecutablePath' => 'C:\\WINDOWS\\system32\\svchost.exe',
'RemoteAddr' => '0.0.0.0'
}
],
...
[
'192.168.169.150:1841',
{
'RemotePort' => 80,
'LocalPort' => 1841,
'LocalAddr' => '192.168.169.150',
'State' => 'ESTABLISHED',
'ProcessId' => 1868,
'ProcessName' => 'firefox.exe',
'ProcessExecutablePath' => 'C:\\Program Files\\Mozilla Firefox\\firefox.exe',
'RemoteAddr' => '69.59.196.211'
}
],
Phewwww es war anstrengend verbindet alle diese Punkte.
Auf welcher Plattform? Windows? – innaM
Sorry, ja auf Windows – Xetius
@Xetius Ich denke, ich kam mit einer funktionierenden Lösung. Bitte testen Sie es und lassen Sie mich wissen, ob es funktioniert. –