How to find the top IP addresses from IIS logs?
To find the top IP address in the IIS log, 1. Use Log Parser Studio: Load the log file and run SQL to query the IP frequency to generate CSV sorting output; 2. Use PowerShell: Read the log content, skip the header, extract the IP fields and group statistics, and sort in descending order of the number of times; 3. Use AWK SORT: Extract IP, sort, count the number of times and arrange it in descending order of the number of times; Note that the positions of the IP fields in different log formats may be different, and you need to adjust according to the actual situation to ensure the extraction is accurate.
To find the top IP addresses in IIS logs, the core is to analyze the log files, count the frequency of each IP, and sort it by number. This is useful when troubleshooting access sources, identifying exception requests, or optimizing server resources.

Quickly extract high-frequency IP with Log Parser Studio
Log Parser Studio is a free tool officially provided by Microsoft to efficiently analyze IIS logs. The operation steps are as follows:
- Open Log Parser Studio and load your IIS log file (usually with the .log suffix)
- Enter the following SQL query statement:
SELECT c-ip AS ClientIP, COUNT(*) AS Hits INTO top_ips.csv FROM '[LOGFILEPATH]' GROUP BY c-ip ORDER BY Hits DESC
- After running, a CSV file is generated, which lists all accessed IPs and their access times, sorted from high to low by number of visits.
This method is suitable for people with a certain technical foundation, and is efficient and supports batch processing of multiple log files.

Use PowerShell to simply count the number of IP occurrences
If you don't want to install extra tools, PowerShell can also complete basic statistics. Here is an example of a common command:
Get-Content C:\inetpub\logs\LogFiles\W3SVC1\u_ex231001.log | Select-Object -Skip 4 | ForEach-Object { ($_ -split ' ')[5] } | Group-Object | Sort-Object Count -Descending | Select-Object Name, Count
The purpose of this script is:

- Ignore the first 4 lines (log header information)
- Split each line by space and extract the 5th field (i.e. IP address)
- Count the number of occurrences of each IP
- Arrange in descending order
Note: The log formats of different servers are slightly different, and the location of the IP field may not be the fifth one, and it needs to be adjusted according to the actual situation.
Using AWK SORT (for Linux environments)
If you process IIS logs on a Linux system (such as via WSL or exporting to a Linux server), you can use the following command combination:
awk '{print $5}' u_ex231001.log | sort | uniq -c | sort -nr
Let's explain:
-
awk '{print $5}'
Extract IP address (field location depends on log format) -
sort
the IP to deduplicate -
uniq -c
counts the number of occurrences of each IP -
sort -nr
is sorted in descending order of numbers
This method is very fast on the command line and is suitable for handling large log files.
Tips: Pay attention to log format and field location
The field order of IIS logs is not fixed, it depends on the log format you configure (such as W3C, NCSA, customization, etc.). Check the field definitions in the first few lines of the log file and confirm the field location where the IP is located. Otherwise, the extracted IP will have an error.
For example, the default IP of W3C format is the 5th field, but if there are other fields in your log, the location may change.
Basically these methods. You can choose tools based on your environment and habits. Either way, the key is to accurately identify the IP fields and count the frequency.
The above is the detailed content of How to find the top IP addresses from IIS logs?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

TorunmultiplewebsitesonasingleIISserverwithoutseparateIPaddresses,usehostheaders.1.AssignallsitesthesameIPandport(like80or443)inIISbindings.2.SetuniquehostheadersforeachsiteviatheBindingsmenu.3.EnsureDNSArecordspointeachdomaintotheserver'ssharedIP.Co

Application pool crashes can quickly locate the causes by analyzing the IIS log. 1. First check the W3SVC log at the crash time point, search for 503 errors, and determine whether it is caused by application pool crash or frequent recycling; 2. Combine the HTTPERR log to check whether there are any underlying error entries such as Connection_Dropped or RequestQueueFull, and confirm that the backend cannot respond; 3. Check the application and system logs in the event viewer, find events such as 5002, 5015, 5017 from WAS or IIS-WMSVC sources, and confirm that the application pool life cycle abnormality; 4. Troubleshoot common causes, such as code exceptions, unavailability of dependency resources, rapid failure triggering, memory leaks, etc., and combine debugging tools

IIS logs on multiple servers can be implemented in the following ways: 1. Use Windows event forwarding, suitable for scenarios where logs have been written to event logs, create subscriptions on the central server and configure forwarding rules on each IIS server; 2. Use file sharing scripts to collect regularly, suitable for small environments, use scripts to copy log files from each server regularly, combining robocopy or xcopy with scheduled task execution; 3. Deploy log collection tools such as Logstash, NXLog, Fluentd, suitable for large-scale environments, support automatic collection, filtering, compression and forwarding, and have failed retry and breakpoint continuous transmission functions. In addition, it is necessary to unify the log path, configure access permissions, pay attention to the log rotation mechanism and consider compression

The key to configuring IIS logging in a load balancing environment is to ensure log integrity and traceability. 1. Enable and configure IIS logging, use W3C to extend the log format, unify the log storage path, and set reasonable log scrolling frequency. 2. Record the client's real IP, set the X-Forwarded-For header through the load balancer, and configure the URL rewrite module and ARR on IIS to write it to the log. 3. Implement centralized log management and time synchronization, use tools such as ELK or Splunk to collect logs in a centralized manner, and ensure that all server time zones are consistent and NTP synchronization is enabled. 4. Avoid log duplication and missing, track request links through X-Request-ID, and record additional information from the application layer.

TosetupURLrewriterulesinIIS,firstinstalltheURLRewritemoduleviaWebPI,WindowsFeatures,orPowerShellwithInstall-WindowsFeature-NameWeb-Url-Auth;next,createbasicrulesusingtheIISManagerGUIbyselectingyoursite,openingURLRewrite,addingarule,andspecifyingmatch

The IISRequestFiltering module can improve website security by configuring blacklist extensions, limiting URLs and querying string lengths, and prohibiting hiding HTTP. The specific steps are: 1. Add extensions such as .php and set to reject to prevent upload vulnerabilities in the "File Extension" tab; 2. Set the URL not more than 2KB and the query string not more than 1024 bytes in the "Request Limit" to prevent abnormal requests; 3. Deny non-essential methods such as PUT, DELETE, TRACE and other methods in the "HTTP Method" tab to reduce the attack surface. These settings are simple and effective, and are suitable for strengthening IIS security protection.

The 200064 status code indicates that the request is successful and there is no system error, but the data transmission volume is small. The specific explanation is as follows: 1.200 means that the HTTP request is successfully processed; 2.0 means that no Windows-level error occurred; 3.64 means that the server sent 64 bytes of data, usually the response header information. Commonly used in HEAD requests, small static file access, crawler detection, or page redirection. If this status code frequently appears in the log, it may indicate that there are a large number of small requests, scanning behaviors, or redirecting pages. There is usually no need to worry, but if the source is abnormal or the number of requests suddenly increases, it is recommended to further check whether there are security risks or optimization needs.

ThedefaultIISlogfilepathisC:\inetpub\logs\LogFiles,butitcanbecustomized.1.EachwebsitehasitsownsubfolderlikeW3SVC1.2.Tofindtheexactpath,openIISManager,selectthesite,andchecktheLoggingsection.3.LogsusetheW3Cformatandcontaindetailslikerequesttime,IPaddr
