├── MultiPortScan ├── App.config ├── PortList.cs ├── Properties │ └── AssemblyInfo.cs ├── MultiPortScan.csproj ├── Program.cs └── PortScanner.cs ├── README.md ├── MultiPortScan.sln ├── LICENSE.txt ├── CONTRIBUTING.md ├── CODE_OF_CONDUCT.md └── .gitignore /MultiPortScan/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /MultiPortScan/PortList.cs: -------------------------------------------------------------------------------- 1 | namespace MultiPortScan 2 | { 3 | class PortList 4 | { 5 | private int start; 6 | private int stop; 7 | private int ports; 8 | 9 | public PortList(int starts, int stops) 10 | { 11 | start = starts; 12 | stop = stops; 13 | ports = start; 14 | } 15 | 16 | public bool MorePorts() 17 | { 18 | return (stop - ports) >= 0; 19 | } 20 | public int NextPort() 21 | { 22 | if (MorePorts()) 23 | { 24 | return ports++; 25 | } 26 | return -1; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C-Sharp-Multi-Threaded-Port-Scanner 2 | C# multithreaded TCP port scanner console application. 3 | 4 | # [Download Software](https://goo.gl/oFJtZf) 5 | 6 | Link to Download software [HERE](https://goo.gl/oFJtZf) 7 | 8 | # Features 9 | 10 | 1) Scan by I.P address or Domain Name. 11 | 2) Choose start and finish ports. 12 | 3) Choose how many concurrent threads to run. 13 | 4) Choose how long to keep connections alive. 14 | 5) Banner/Website header grabbing similar to zenmap/Nmap. 15 | 6) Website webpage title grabber. 16 | 17 | 18 | # [Usage](https://www.youtube.com/watch?v=Yz7OlUGdh_c) 19 | 20 | To see a Basic operation of the software click here [My Youtube Channel](https://www.youtube.com/watch?v=Yz7OlUGdh_c) 21 | 22 | 23 | 24 | # Plans for the future 25 | make all functions available equal to zenmap ,nmap and advanced port scanner etc.. 26 | 27 | Hopefully with some help from the community on github. 28 | 29 | Philip M 30 | -------------------------------------------------------------------------------- /MultiPortScan.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Express 14 for Windows Desktop 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiPortScan", "MultiPortScan\MultiPortScan.csproj", "{3D046CB3-EBC4-4F3D-BD30-2072D5D84759}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3D046CB3-EBC4-4F3D-BD30-2072D5D84759}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {3D046CB3-EBC4-4F3D-BD30-2072D5D84759}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {3D046CB3-EBC4-4F3D-BD30-2072D5D84759}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {3D046CB3-EBC4-4F3D-BD30-2072D5D84759}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Philip Murray 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Contribution 4 | 5 | Thank you for considering contribution to the Multi-Threaded-Port-Scanner Project! How to contribute? 6 | 7 | It's very simple! 8 | 9 | 1.Fork the project 10 | 2.Make the changes 11 | 3.Issue a pull request 12 | 4.I will do a merge after verifying (in some cases changing) the code 13 | 14 | How to report bugs? 15 | 16 | You can simply use the Issues section on github Just write an issue, and i will try to respond within 24 hours! How to contribute? (without writing code) 17 | 18 | You can also do this on the Issues section, and i will label it as enhancement This way you can suggest new features, or change an older one without coding. I will try to respond within 24 hours! How to run / compile 19 | 20 | I use Visual Studio 2017 Community Edition or Visual Studio 2015 Express for Windows Desktop. The project is in c#, built with .NET Framework 4.5 21 | 22 | How to ask questions? 23 | 24 | You can also use the Issues section on GitHub, i will assign a label to it, so it's different from bugs. 25 | I will try to respond within 24 hours! You can also contact me at [My Youtube Channel](https://www.youtube.com/channel/UCAnWN8gy4oA1YbA9m8aVZ4Q) Either a comment on the video about the topic, or a message at the Discussion section on my channel page 26 | -------------------------------------------------------------------------------- /MultiPortScan/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("MultiPortScan")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MultiPortScan")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("3d046cb3-ebc4-4f3d-bd30-2072d5d84759")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /MultiPortScan/MultiPortScan.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {3D046CB3-EBC4-4F3D-BD30-2072D5D84759} 8 | Exe 9 | Properties 10 | MultiPortScan 11 | MultiPortScan 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 61 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [My Youtube Channel](https://www.youtube.com/channel/UCAnWN8gy4oA1YbA9m8aVZ4Q). The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /MultiPortScan/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MultiPortScan 4 | { 5 | /// 6 | /// A Console type Multi Port TCP Scanner 7 | /// Author : Philip Murray 8 | /// 9 | 10 | class Program 11 | { 12 | 13 | static void Main(string[] args) 14 | { 15 | string host; 16 | int portStart; 17 | int portStop; 18 | int Threads; 19 | int timeout; 20 | 21 | youGotItWrong: //goto: Start Again 22 | 23 | //this is for the user to select a host ip 24 | string ip; 25 | Console.ForegroundColor = ConsoleColor.Yellow; 26 | Console.WriteLine("Enter Host I.P or Domain example: (127.0.0.1) or (localhost) etc.."); 27 | Console.ResetColor(); 28 | Console.Write("Enter Host I.P or Domain : "); 29 | ip = Console.ReadLine(); 30 | Console.WriteLine(); 31 | host = ip; 32 | 33 | //this is for the user to select the start port 34 | string startPort; 35 | Console.ForegroundColor = ConsoleColor.Yellow; 36 | Console.WriteLine("Min Start Port : 0"); 37 | Console.ResetColor(); 38 | Console.Write("Enter A start Port : "); 39 | startPort = Console.ReadLine(); 40 | Console.WriteLine(); 41 | 42 | //THIS CHECKS TO SEE IF IT THE START PORT CAN BE PARSED OUT 43 | int number; 44 | bool resultStart = int.TryParse(startPort, out number); 45 | 46 | if (resultStart) 47 | { 48 | portStart = int.Parse(startPort); 49 | } 50 | 51 | else 52 | { 53 | Console.WriteLine("Try Again NOOOB!!"); 54 | goto youGotItWrong; 55 | // return; 56 | } 57 | 58 | 59 | //this is for the end port 60 | string endPort; 61 | Console.ForegroundColor = ConsoleColor.Yellow; 62 | Console.WriteLine("Max End Port : 65535"); 63 | Console.ResetColor(); 64 | Console.Write("Enter A End Port : "); 65 | endPort = Console.ReadLine(); 66 | Console.WriteLine(); 67 | 68 | 69 | //THIS CHECKS TO SEE IF IT THE END PORT CAN BE PARSED OUT 70 | int number2; 71 | bool resultEnd = int.TryParse(endPort, out number2); 72 | 73 | if (resultEnd) 74 | { 75 | portStop = int.Parse(endPort); 76 | } 77 | 78 | else 79 | { 80 | Console.WriteLine("Try Again NOOOB!!"); 81 | 82 | goto youGotItWrong; 83 | // return; 84 | } 85 | 86 | //this is how many threads will be started 87 | string threadsToRun; 88 | Console.ForegroundColor = ConsoleColor.Yellow; 89 | Console.WriteLine("Normal Thread amount is between 1 - 50 (less threads = higher accuracy)"); 90 | Console.ResetColor(); 91 | Console.Write("Enter How Many Threads To Run : "); 92 | threadsToRun = Console.ReadLine(); 93 | Console.WriteLine(); 94 | 95 | 96 | //THIS CHECKS TO SEE IF IT THE END PORT CAN BE PARSED OUT 97 | int number3; 98 | bool resultThreads = int.TryParse(threadsToRun, out number3); 99 | 100 | if (resultThreads) 101 | { 102 | Threads = int.Parse(threadsToRun); 103 | } 104 | 105 | else 106 | { 107 | Console.WriteLine("Try Again NOOOB!!"); 108 | 109 | goto youGotItWrong; 110 | 111 | // return; 112 | } 113 | 114 | //this is how many threads will be started 115 | string tcpTimeout; 116 | Console.ForegroundColor = ConsoleColor.Yellow; 117 | Console.WriteLine("Normal Timeout amount is between 1 - 10 secs ( 1 = 1 second)(higher timeout = higher accuracy)"); 118 | Console.ResetColor(); 119 | Console.Write("Enter Timeout : "); 120 | tcpTimeout = Console.ReadLine(); 121 | Console.WriteLine(); 122 | 123 | //THIS CHECKS TO SEE IF IT THE timeout CAN BE PARSED OUT 124 | int number4; 125 | bool resultTimeout = int.TryParse(tcpTimeout, out number4); 126 | 127 | if (resultTimeout) 128 | { 129 | timeout = int.Parse(tcpTimeout) * 1000; 130 | 131 | } 132 | 133 | else 134 | { 135 | Console.WriteLine("Try Again NOOOB!!"); 136 | 137 | goto youGotItWrong; 138 | // return; 139 | } 140 | 141 | try 142 | { 143 | 144 | host = ip; 145 | } 146 | catch (Exception ex) 147 | { 148 | Console.WriteLine(ex.Message); 149 | return; 150 | } 151 | 152 | if (resultStart == true && resultEnd == true) 153 | { 154 | try 155 | { 156 | 157 | portStart = int.Parse(startPort); 158 | portStop = int.Parse(endPort); 159 | 160 | } 161 | catch (Exception ex) 162 | { 163 | Console.WriteLine(ex.Message); 164 | return; 165 | } 166 | 167 | } 168 | if (resultThreads == true) 169 | { 170 | try 171 | { 172 | 173 | Threads = int.Parse(threadsToRun); 174 | } 175 | catch (Exception ex) 176 | { 177 | Console.WriteLine(ex.Message); 178 | 179 | return; 180 | } 181 | } 182 | 183 | PortScanner ps = new PortScanner(host, portStart, portStop , timeout); 184 | ps.start(Threads); 185 | 186 | } 187 | 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /MultiPortScan/PortScanner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | using System.Text; 6 | using System.Text.RegularExpressions; 7 | using System.Threading; 8 | 9 | namespace MultiPortScan 10 | { 11 | class PortScanner 12 | { 13 | 14 | private string host; 15 | private PortList portList; 16 | private int workThread = 0; 17 | private int count = 0; 18 | public int tcpTimeout ; 19 | 20 | private class isTcpPortOpen 21 | { 22 | public TcpClient MainClient { get; set; } 23 | public bool tcpOpen { get; set; } 24 | } 25 | 26 | 27 | public PortScanner(string host, int portStart, int portStop , int timeout) 28 | { 29 | this.host = host; 30 | portList = new PortList(portStart, portStop); 31 | tcpTimeout = timeout; 32 | 33 | } 34 | 35 | public void start(int threadCounter) 36 | { 37 | for (int i = 0; i < threadCounter; i++) 38 | { 39 | 40 | Thread thread1 = new Thread(new ThreadStart(RunScanTcp)); 41 | thread1.Start(); 42 | workThread++; 43 | } 44 | 45 | } 46 | 47 | public void RunScanTcp() 48 | { 49 | 50 | int port; 51 | 52 | //while there are more ports to scan 53 | while ((port = portList.NextPort()) != -1) 54 | { 55 | count = port; 56 | 57 | Thread.Sleep(1); //lets be a good citizen to the cpu 58 | 59 | Console.Title = "Current Port Count : " + count.ToString(); 60 | 61 | try 62 | { 63 | 64 | Connect(host, port, tcpTimeout); 65 | 66 | } 67 | catch 68 | { 69 | continue; 70 | } 71 | 72 | Console.ForegroundColor = ConsoleColor.Green; 73 | Console.WriteLine(); 74 | Console.WriteLine("TCP Port {0} is open ", port); 75 | try 76 | { 77 | Console.ForegroundColor = ConsoleColor.Yellow; 78 | //grabs the banner / header info etc.. 79 | Console.WriteLine(BannerGrab(host, port, tcpTimeout)); 80 | 81 | 82 | } 83 | catch (Exception ex) 84 | { 85 | Console.ForegroundColor = ConsoleColor.Red; 86 | Console.WriteLine("Could not retrieve the Banner ::Original Error = " + ex.Message); 87 | Console.ResetColor(); 88 | } 89 | Console.ForegroundColor = ConsoleColor.Green; 90 | string webpageTitle = GetPageTitle("http://" + host + ":" + port.ToString()); 91 | 92 | if(!string.IsNullOrWhiteSpace(webpageTitle)) 93 | { 94 | //this gets the html title of the webpage 95 | Console.WriteLine("Webpage Title = " + webpageTitle + "Found @ :: " + "http://" + host + ":" + port.ToString()); 96 | 97 | } 98 | else 99 | { 100 | Console.ForegroundColor = ConsoleColor.DarkMagenta; 101 | Console.WriteLine("Maybe A Login popup or a Service Login Found @ :: " + host + ":" + port.ToString()); 102 | Console.ResetColor(); 103 | } 104 | 105 | 106 | Console.ResetColor(); 107 | 108 | } 109 | 110 | 111 | if (Interlocked.Decrement(ref workThread) == 0) 112 | { 113 | Console.WriteLine(); 114 | Console.WriteLine("Scan Complete !!!"); 115 | 116 | Console.ReadKey(); 117 | 118 | } 119 | 120 | } 121 | //method for returning tcp client connected or not connected 122 | public TcpClient Connect(string hostName, int port, int timeout) 123 | { 124 | var newClient = new TcpClient(); 125 | 126 | var state = new isTcpPortOpen 127 | { 128 | MainClient = newClient, tcpOpen = true 129 | }; 130 | 131 | IAsyncResult ar = newClient.BeginConnect(hostName, port, AsyncCallback, state); 132 | state.tcpOpen = ar.AsyncWaitHandle.WaitOne(timeout, false); 133 | 134 | if (state.tcpOpen == false || newClient.Connected == false) 135 | { 136 | throw new Exception(); 137 | 138 | } 139 | return newClient; 140 | } 141 | 142 | //method for Grabbing a webpage banner / header information 143 | public string BannerGrab(string hostName, int port, int timeout) 144 | { 145 | var newClient = new TcpClient(hostName ,port); 146 | 147 | 148 | newClient.SendTimeout = timeout; 149 | newClient.ReceiveTimeout = timeout; 150 | NetworkStream ns = newClient.GetStream(); 151 | StreamWriter sw = new StreamWriter(ns); 152 | 153 | //sw.Write("GET / HTTP/1.1\r\n\r\n"); 154 | 155 | sw.Write("HEAD / HTTP/1.1\r\n\r\n" 156 | + "Connection: Closernrn"); 157 | 158 | sw.Flush(); 159 | 160 | byte[] bytes = new byte[2048]; 161 | int bytesRead = ns.Read(bytes, 0, bytes.Length); 162 | string response = Encoding.ASCII.GetString(bytes, 0, bytesRead); 163 | 164 | return response; 165 | } 166 | 167 | 168 | //async callback for tcp clients 169 | void AsyncCallback(IAsyncResult asyncResult) 170 | { 171 | var state = (isTcpPortOpen)asyncResult.AsyncState; 172 | TcpClient client = state.MainClient; 173 | 174 | try 175 | { 176 | client.EndConnect(asyncResult); 177 | } 178 | catch 179 | { 180 | return; 181 | } 182 | 183 | if (client.Connected && state.tcpOpen) 184 | { 185 | return; 186 | } 187 | 188 | client.Close(); 189 | } 190 | 191 | static string GetPageTitle(string link) 192 | { 193 | try 194 | { 195 | 196 | WebClient x = new WebClient(); 197 | string sourcedata = x.DownloadString(link); 198 | string getValueTitle = Regex.Match(sourcedata, @"\]*\>\s*(?[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value; 199 | 200 | return getValueTitle; 201 | 202 | } 203 | catch (Exception ex) 204 | { 205 | Console.ForegroundColor = ConsoleColor.Red; 206 | Console.WriteLine("Could not connect. Error:" + ex.Message); 207 | Console.ResetColor(); 208 | return ""; 209 | } 210 | 211 | 212 | } 213 | 214 | } 215 | } 216 | --------------------------------------------------------------------------------