Skip to content
GitHubStars: 010 views

powershell-ip-scanner

A PowerShell script to quickly scan a local network and discover IPs, MAC addresses, and hostnames.

Network Scanner with PowerShell (ipscan.ps1)

This PowerShell script allows you to scan a range of IP addresses on your local network to discover active devices. For each device found, it will attempt to retrieve its IP address, MAC address, and hostname.

Features

  • Easy to use: Interactively prompts for the network and range to scan.
  • Host detection: Uses ping (Test-Connection) to verify if a host is active.
  • Detail retrieval:
    • Resolves the hostname via DNS.
    • Retrieves the MAC address from the system's ARP table.
  • Multiple Output:
    • Displays results in a clear table in the console.
    • Automatically saves results to a CSV file with a timestamp.

Requirements

  • Windows with PowerShell 5.1 or higher.
  • It is recommended to run PowerShell with Administrator privileges to ensure that retrieving the MAC address (Get-NetNeighbor) works correctly.

How to run the script?

For security reasons, PowerShell has an "execution policy" that restricts script execution. To be able to run ipscan.ps1 safely and only for this session, follow these steps:

1. Open PowerShell as Administrator

  • Right-click on the Windows Start menu.
  • Select "Windows PowerShell (Admin)" or "Terminal (Admin)".

2. Navigate to the script folder

Use the cd command to move to the directory where you saved the ipscan.ps1 file.

# Example: if the script is in your Downloads folder
cd C:\Users\USER\Downloads\ipscan

3. Adjust the execution policy for the current session

Run the following command. This will allow local scripts (like this one) to run only in the PowerShell window you have open. It does not modify your system's global security configuration.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process

4. Run the script

Now, simply run the script as follows:

.\ipscan.ps1

5. Enter the range to scan

The script will ask you to enter the network and the range. The format is the base IP (the first three octets) followed by the starting and ending last octet, separated by a hyphen.

Please enter the network and range to scan (e.g., 192.168.1.1-254)

Input example: 192.168.1.1-254

Script Output

  • In the console: You will see the scan progress in real-time. Upon completion, a table with all active devices found will be displayed, sorted by IP.
  • CSV File: A file named Resultados_Scan_YYYY-MM-DD_HH-mm-ss.csv will be created in the same folder as the script. This file contains the same information as the table and can be opened with Excel or other spreadsheet software.

Script designed to be compatible and educational. For large-scale or professional-level network scans, the use of specialized tools like Nmap is recommended.