Search code examples
powershelliiswebserverwindows-server

How can I list all active and unique ips connections in a IIS server


I'm trying list all active connections in an IIS Server and i don´t know how to make this happen. I'm studying about some methods and trying to make a script in Powershell which extracts a number of all connections in an specific port (like 80 port) and a number of unique connections in a specific port (like 80 port).

I need this information because in some cases I have multiple access to this server based on the same IP, so I need filter this IPs access and look two numbers, one which show all active connections and another which show all unique connections.

Thanks for the help!!


Solution

  • Solved!

    Instead of using netstat commands, i´ve used the Get-NetTCPConnection resource, based on these articles.

    So, i filtered all connections established in the port 80 and group by the foreign address (named as RemoteAddress).

    • $count_unique_ips = Get-NetTCPConnection -LocalPort 80 -State Established | group RemoteAddress -NoElement
    • $count_unique_ips.count

    And based on that link I've solved the problem of list all connections in port 80.

    • $c = netstat –aon | findstr ":80" | select-string “ESTABLISHED” ;
    • $c.count