Scan Your Network Efficiently: PowerShell IPv4 Network Scanner

Description

This robust asynchronous IPv4 network scanner for PowerShell empowers you to scan any IPv4 range, from specific segments like 172.16.1.47 to 172.16.2.5, to entire subnets. Subnet scanning is easily achieved by specifying an IPv4 address within the target subnet and its corresponding subnet mask or CIDR notation.

By default, the scanner provides essential information: the IPv4 address, its status (Up or Down), and the hostname. For more detailed insights, you can customize the output using parameters to display additional values (refer to Get-Help for comprehensive parameter details).

To maximize scanning speed and efficiency, this script leverages a RunspacePool. This technique distributes scanning tasks across all CPU cores, ensuring optimal performance, as demonstrated in the CPU usage screenshot below.

If you’re seeking a more integrated solution, this script is also available as a function within a dedicated PowerShell module, which you can find here.

For those interested in expanding their network scanning toolkit, consider exploring my asynchronous IPv4 Port Scanner, designed to complement this network scanner.

Syntax

.IPv4NetworkScan.ps1 [-StartIPv4Address] <IPAddress> [-EndIPv4Address] <IPAddress> [[-Tries] <Int32>] [[-Threads] <Int32>] [[-DisableDNSResolving]] [[-EnableMACResolving]] [[-ExtendedInformations]] [[-IncludeInactive]] [<CommonParameters>]

.IPv4NetworkScan.ps1 [-IPv4Address] <IPAddress> [-Mask] <String> [[-Tries] <Int32>] [[-Threads] <Int32>] [[-DisableDNSResolving]] [[-EnableMACResolving]] [[-ExtendedInformations]] [[-IncludeInactive]] [<CommonParameters>]

.IPv4NetworkScan.ps1 [-IPv4Address] <IPAddress> [-CIDR] <Int32> [[-Tries] <Int32>] [[-Threads] <Int32>] [[-DisableDNSResolving]] [[-EnableMACResolving]] [[-ExtendedInformations]] [[-IncludeInactive]] [<CommonParameters>]

Example 1

PS> .IPv4NetworkScan.ps1 -StartIPv4Address 192.168.178.0 -EndIPv4Address 192.168.178.20

IPv4Address     Status Hostname
-----------     ------ --------
192.168.178.1   Up     fritz.box

This example demonstrates a scan across a specific IP address range, from 192.168.178.0 to 192.168.178.20. The output displays the IPv4 address, its status (Up indicating it’s reachable), and the resolved hostname if DNS resolution is successful.

Example 2

PS> .IPv4NetworkScan.ps1 -IPv4Address 192.168.178.0 -Mask 255.255.255.0 -DisableDNSResolving

IPv4Address     Status
-----------     ------
192.168.178.1   Up
192.168.178.22  Up

In this example, the script scans the entire 192.168.178.0/24 subnet, defined by the IP address 192.168.178.0 and the subnet mask 255.255.255.0. The -DisableDNSResolving parameter is used to speed up the scan by skipping hostname lookups, resulting in output showing only the IPv4 address and status.

Example 3

PS> .IPv4NetworkScan.ps1 -IPv4Address 192.168.178.0 -CIDR 25 -EnableMACResolving

IPv4Address     Status Hostname         MAC               Vendor
-----------     ------ --------         ---               ------
192.168.178.1   Up     fritz.box        XX-XX-XX-XX-XX-XX AVM Audiovisuelles Marketing und Computersysteme GmbH
192.168.178.22  Up     XXXXX-PC.fritz.box XX-XX-XX-XX-XX-XX ASRock Incorporation

This final example scans a subnet defined by the IP address 192.168.178.0 and the CIDR notation /25. The -EnableMACResolving parameter is used to retrieve and display the MAC address and vendor information for each active IP address, providing extended network device details. This example showcases the script’s ability to gather comprehensive information about devices on your network.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *