Open Port Scanning

Open Port Scanning

PowerShell script that uses the Test-NetConnection cmdlet to scan for open TCP ports on a given IP address. Please note that this script only scans TC

Disable/Enable all Network Adapters
Managing VMware Snapshots with Powershell
Changing PWDLASTSET in Active Directory

PowerShell script that uses the Test-NetConnection cmdlet to scan for open TCP ports on a given IP address. Please note that this script only scans TCP ports and does not scan UDP ports because UDP is a connectionless protocol and doesn’t respond to connection attempts in the same way TCP does.

# Define the target IP address and the range of ports to scan
$targetIP = "192.168.1.1"
$portStart = 1
$portEnd = 1024

# Loop through the range of ports
for ($port = $portStart; $port -le $portEnd; $port++) {
    $result = Test-NetConnection -ComputerName $targetIP -Port $port -InformationLevel Quiet

    # If the port is open, print a message
    if ($result -eq $true) {
        Write-Output "Port $port is open on $targetIP"
    }
}

This script will output a message for each open port it finds. You can replace "192.168.1.1" with the IP address you want to scan, and adjust $portStart and $portEnd to set the range of ports to scan.

Please note that scanning networks can be seen as aggressive behavior and may violate the terms of service of your network or ISP. Always get permission before scanning a network that doesn’t belong to you. Also, this script may take a long time to run if you’re scanning a large number of ports.

This script is a very basic example and may not suit your exact needs. For a more robust solution, you might want to consider using a dedicated network scanning tool like Nmap. Nmap is a free and open-source network scanner that can scan both TCP and UDP ports. It’s widely used by network administrators for tasks like network inventory, managing service upgrade schedules, and monitoring host or service uptime.

 

COMMENTS

WORDPRESS: 0