![]() |
|
[Shell] [PowerShell] TCP Port Scanner - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Shell] [PowerShell] TCP Port Scanner (/showthread.php?tid=5698531) |
[PowerShell] TCP Port Scanner - Travelers - Aug 19, 2017 Been messing with this thing for about a day now. I'm by no means a coding expert so I'm pretty thrilled I was able to make my first port scanner. This thing only scans TCP ports, and you are able to define the ports/port range you want to scan. I put plenty of comments in there, also. If you find any errors while running it, please let me know so I can correct them. Also feel free to tweak based on your needs or make your own improvements. Code # PowerShell port scanner v 0.1.3* - HFDone - Aug 20, 2017 close the TcpClient if its open * - Travelers - Aug 20, 2017 (Aug 20, 2017 08:38 AM)HFDone Wrote: close the TcpClient if its open Would you be able to elaborate on that? Why would I need to do this if I'm just checking to see if the ports are open? Are you suggesting that I leave a $scan.dispose at the end of the script? * - HFDone - Aug 20, 2017 you open it, when you done you close it ! $scan.Connect($remoteIP, $port); if ($scan.Connected()) {$scan.Close()} * - Travelers - Aug 20, 2017 (Aug 20, 2017 10:16 AM)HFDone Wrote: you open it, when you done you close it ! Yes, ok. Close it when I'm done. But could you explain why? * - HFDone - Aug 20, 2017 why not ? you have 1024 open connection do nothing * - Travelers - Aug 20, 2017 (Aug 20, 2017 12:32 PM)HFDone Wrote: why not ? you have 1024 open connection do nothing Right. I was looking for a much more detailed answer, but Google saved the day. Thanks, Google. (Aug 20, 2017 10:16 AM)HFDone Wrote: you open it, when you done you close it ! Adding this section, as you have described, in the script causes it to not work correctly. I have added $scan.dispose() to clean up resources that were being used by the $scan object, inside the Function that I called. This is more tidy and adds fewer characters to the code overall. Thank you for suggesting this. * - HFDone - Aug 20, 2017 if ($scan.Connected()) {Write-Host "Port $Port is up";$scan.Close()} |