Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Test each port individually against any external host
- # note: script will also accept `.\test-netconnect -ComputerName <IPv4_addr>`
- # if you choose to execute as if it's just Test-NetConnection
- param (
- [Parameter(Mandatory=$true, HelpMessage="Enter the target IPv4 address")]
- [string]$ComputerName = (Read-Host "Please enter the target IPv4 address")
- )
- # Test each port individually against any external host
- Test-NetConnection w3.org -Port 443
- # Quick one-liner to test multiple ports against the provided external host
- $ports = 8000,8001,8002,22,53,80,443,5000,5001,5002
- $ports | ForEach-Object {
- $port = $_;
- if (Test-NetConnection -ComputerName $ComputerName -Port $port -InformationLevel Quiet -WarningAction SilentlyContinue) {
- "Port $port is open"
- } else {
- "Port $port is closed"
- }
- }
Add Comment
Please, Sign In to add comment