Perl 或 Java 端口上运行的应用程序的名称

发布于 2024-08-02 21:53:55 字数 168 浏览 5 评论 0原文

Xampp 附带了一个名为 xampp-portcheck.exe 的简洁可执行文件。如果所需的端口空闲,则会响应,如果不空闲,则响应哪些应用程序正在这些端口上运行。

我可以通过访问 netstat 详细信息来检查某个端口上是否正在运行某些内容,但是如何在 Windows 中找出该端口上运行的应用程序呢?

Xampp comes with a neat executable called xampp-portcheck.exe. This responds with if the ports required are free, and if not, which applications are running on those ports.

I can check if something is running on a port, by accessing the netstat details, but how do I find out the application running on the port within Windows?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月无声 2024-08-09 21:53:55

CPAN 模块 Win32::IPHelper 提供对 GetExtendedTcpTable 为每个连接提供ProcessID

Win32::Process::Info 提供有关所有正在运行的进程的信息。

将两者结合起来,我们得到:

#!/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;

输出:

  [
    '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连接所有这些点非常费力。

The CPAN module Win32::IPHelper provides access to GetExtendedTcpTable which provides the ProcessID for each connection.

Win32::Process::Info gives information about all running processes.

Combining the two, we get:

#!/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;

Output:

  [
    '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 it was exhausting connecting all these dots.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文