skip to Main Content

EDITED
my goal :
get “total” list of IP’s connected to port 80 in windows server.


TOTAL IP's
5 1.1.1.1
12 2.2.2.2
1 3.3.3.3

in centos, i found this
netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head

but if windows server, is there any way do that using powershell or cmd?

*i get one example but its not reaching my goal :
netstat -n | find "80"

credit for example : https://mkyong.com/linux/list-all-ip-addresses-connected-to-your-server/

2

Answers


  1. Get-NetTCPConnection is the PowerShell equivalent and creates a robust object you can filter to your needs.

    In your example, you’re getting all connections to port 80 on your device, here’s what that looks like in 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
    
    

    If you wanted to gather just the remote IP addresses, for instance:

    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
    

    If you need to group them to see how many sessions per IP, you can pipe into the Group-Object cmdlet like so:

    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
    
    Login or Signup to reply.
  2. One quick and dirty way to find TCP sessions connected to port 80 is

    for /f "tokens=3" %a in ('netstat -n ^| find ":80 "') do @echo %a > filename.txt
    

    You would obtain output similar to the following:

    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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search