[int[]]$port = 80..83
$net = "131.219.230"
$r = 153..153
#beginning of ip scan
foreach ($range in $r) {
$ip = "{0}.{1}" -F $net,$range
$ip
#beginning of port scan
foreach ($p in $port){
try {
$buffer = new-object System.Byte[] 1026;
$socket = New-Object System.Net.Sockets.tcpClient($ip, $p)
if($socket.Connected) {"port $p is open"}
}
catch { "port $p is Closed"}
} #end of port scan
} #end of ip scan
This will give you results like.
portscan.ps1
192.168.1.1
port 80 is open
port 81 is Closed
port 82 is Closed
port 83 is Closed
Or something like that. you can also make the port look like 80,443,etc to specify specific ports to check. and the r is the range. so if you wanted to check from ip addresses 2..255 then you could. though since this is not parallel and doing tcp connections this is extremely slow. though it gives you an idea on how it could be done.
Thanks for reading,
local tech repair admin
No comments:
Post a Comment