Here’s a script to scan an entire IP range. It allows to find out what IP addresses are free and what are used and displays some basics informations for the used IPs (hostname, mac address, response time); then, the script generates an HTML report with the results.

    IpRangeScan - Scans an IP Range.
    IpRangeScan - Scans an IP Range and generate a report with some informations (hostname, mac address, response time) if the IP address is used
    Defines the IP address range to scan.
    File Name  : IpRangeScan.ps1
    Author     : Fabrice ZERROUKI - fabricezerrouki@hotmail.com
    PS D:\>IpRangeScan.ps1 -range 192.168.1
    The script will scan all IP addresses from to
    [Parameter(Mandatory=$true, HelpMessage="You must provide a IP addresses range to be scanned.")]

$report="$env:TEMP" + "\IpRangeScan.hta"
#Delete previous results file if exists
if ((Get-Item $report -ErrorAction "SilentlyContinue").Exists) {Write-Host "Deleting old $report`n" -ForegroundColor Yellow; Remove-Item $report}
$ScanDate=Get-Date -Format "dd/MM/yyyy HH:mm:ss"
Write-Host "`nRunning the IP address scan for the range $range.xxx`n" -ForegroundColor Yellow

function Get-Mac($line)
$macRegex=[regex] "([0-9a-fA-F]{2}-){5}([0-9a-fA-F]{2})"
function Get-Ping($line)
$pingRegex=[regex] "temps=\d+ ms"

1..254 | ForEach {
if (!(Test-Connection -Count 1 -ComputerName "$range.$_" -Quiet))
Write-Host "$range.$_ is Free" -ForegroundColor DarkGreen
$status = @{
  'MAC Address'="N/A";
  'Response Time'="N/A";
  'IP Address'="$range.$_";
  'Availability'="<span style='color: green;'>Free</span>";
 $obj=New-Object -TypeName PSObject -Property $status
else {
Write-Host "$range.$_ is Used" -ForegroundColor DarkRed
$IpAddress="$range" + "." + "$_"
if ($computername -eq $null) {$computername = "unable to get the hostname"}

$arp=cmd /c "arp -a $IpAddress"
$mac=Get-Mac $arp | Select-Object -ExpandProperty Value
$ping=cmd /c "ping $IpAddress -n 1"
$reply=get-ping $ping | Select-Object -ExpandProperty Value
$reply=$reply -replace "temps=", ""

$status = @{
  'MAC Address'="$mac";
  'Response Time'="$reply";
  'IP Address'="$range.$_";
  'Availability'="<span style='color: orangered;'>Used</span>";
 $obj=New-Object -TypeName PSObject -Property $status

	<title>IP Range Scan Results</title> 
	<style type="text/css">
	h1 {margin: 0; padding: 0; position: relative; background: #104E8B;color: #FFF;}
	body {font: 12px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;}
	table{border: 1px dotted #CCC; font-family: Arial, Helvetica, sans-serif; font-size: 12px; width:100%;}
	th{background-color: #104E8B; color: #FFF; font-weight: bold; text-align:left; vertical-align:top;}
	td{border: 1px dotted #CCC; text-align:left; vertical-align:top;}
	#page-wrap { width: 50%; margin: 100px auto; }
	#bottom {clear:both; text-align:right;}
	<h1>&nbsp;IP Range Scan Results</h1><br />
	<li>Scan Date: $ScanDate</li>
	<li>IP Range scanned: $Range.xxx</li>
	<div id="bottom">&copy; IpRangeScan.ps1 - 2012</div>
Write-Host "`nGenerating the report`n" -ForegroundColor Yellow
$results | ConvertTo-HTML -Head $style -Body $body -PostContent $bottom  | % {$tmp = $_ -replace "&lt;","<"; $tmp -replace "&gt;",">";} |Out-File $report
Start-Sleep 2
Invoke-Expression $report

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top