Windows 获取使用Powershell/CMD连接到服务器的所有IP地址列表

Windows 获取使用Powershell/CMD连接到服务器的所有IP地址列表,windows,powershell,Windows,Powershell,已编辑 我的目标是: 获取连接到windows server中端口80的IP的“总数”列表 总知识产权 5 1.1.1.1 12 2.2.2.2 1 3.3.3.3 在centos,我找到了这个 netstat-tn2>/dev/null | grep:80 | awk'{print$5}'| cut-d:-f1 | sort | uniq-c | sort-nr | head 但如果是windows server,有没有任何方法可以使用powershell或cm

已编辑 我的目标是: 获取连接到windows server中端口80的IP的“总数”列表


总知识产权
5      1.1.1.1
12     2.2.2.2
1      3.3.3.3

在centos,我找到了这个
netstat-tn2>/dev/null | grep:80 | awk'{print$5}'| cut-d:-f1 | sort | uniq-c | sort-nr | head

但如果是windows server,有没有任何方法可以使用powershell或cmd实现这一点

*我举了一个例子,但没有达到我的目标:
netstat-n |查找“80”


例如:

Get nettcpcconnection
是与PowerShell等效的,它创建了一个健壮的对象,您可以根据需要进行筛选

在您的示例中,您将获得设备上端口80的所有连接,下面是PowerShell中的情况:

Get-NetTCPConnection |where RemotePort -eq 80

LocalAddress                        LocalPort RemoteAddress                       RemotePort State       AppliedSetting OwningProcess
------------                        --------- -------------                       ---------- -----       -------------- -------------
192.168.0.27                        51135     50.63.202.49                        80         CloseWait   Internet       12508
192.168.0.27                        51134     50.63.202.49                        80         CloseWait   Internet       12508
192.168.0.27                        51133     50.63.202.49                        80         CloseWait   Internet       12508
192.168.0.27                        51132     50.63.202.49                        80         CloseWait   Internet       12508

如果只想收集远程IP地址,例如:

Get-NetTCPConnection |where RemotePort -eq 80 |select RemoteAddress

RemoteAddress
-------------
50.63.202.49
50.63.202.49
50.63.202.49
50.63.202.49
50.63.202.49
50.63.202.49
如果需要对它们进行分组以查看每个IP有多少个会话,可以通过管道导入
group对象
cmdlet,如下所示:

Get-NetTCPConnection |where RemotePort -eq 80 |select RemoteAddress |
   group-object -Property RemoteAddress |select Name,Count

Name         Count
----         -----
72.21.91.29      1
23.35.182.63     6

查找连接到端口80的TCP会话的一种快速而肮脏的方法是

for /f "tokens=3" %a in ('netstat -n ^| find ":80 "') do @echo %a > filename.txt
您将获得与以下类似的输出:

10.1.1.3:52025
10.1.1.3:53014
10.1.1.3:53039
10.1.1.3:53044
10.1.1.3:53066

谢谢你的回复,有可能也得到以下IP的“总数”吗?示例34 1.2.3.4 | 5 123.123.123.123。其中34和5是“总计”,PowerShell有一个名为
Group Object
的cmdlet,该cmdlet将提供您想要的总计,我将更新答案。记住投票选出任何有用的答案,并将其标记为答案。谢谢,这个答案真的很像我的目标。对不起,我不能投票(我需要15分钟的声望):s