Skip to content

Commit e00309b

Browse files
committed
* Added About window
* Added class to represent listview information * Added PortChecker class * Added UpdateManager
1 parent 7891532 commit e00309b

13 files changed

Lines changed: 436 additions & 59 deletions

Advanced PortChecker/Advanced PortChecker.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,15 @@
7070
<Generator>MSBuild:Compile</Generator>
7171
<SubType>Designer</SubType>
7272
</ApplicationDefinition>
73+
<Compile Include="Classes\LvCheck.cs" />
74+
<Compile Include="Classes\OperationInformation.cs" />
7375
<Compile Include="Classes\PortChecker.cs" />
7476
<Compile Include="Classes\StyleManager.cs" />
7577
<Compile Include="Classes\Update.cs" />
7678
<Compile Include="Classes\UpdateManager.cs" />
79+
<Compile Include="Windows\AboutWindow.xaml.cs">
80+
<DependentUpon>AboutWindow.xaml</DependentUpon>
81+
</Compile>
7782
<Compile Include="Windows\MainWindow.xaml.cs">
7883
<DependentUpon>MainWindow.xaml</DependentUpon>
7984
</Compile>
@@ -84,6 +89,10 @@
8489
<Compile Include="Windows\SettingsWindow.xaml.cs">
8590
<DependentUpon>SettingsWindow.xaml</DependentUpon>
8691
</Compile>
92+
<Page Include="Windows\AboutWindow.xaml">
93+
<SubType>Designer</SubType>
94+
<Generator>MSBuild:Compile</Generator>
95+
</Page>
8796
<Page Include="Windows\MainWindow.xaml">
8897
<SubType>Designer</SubType>
8998
<Generator>MSBuild:Compile</Generator>
@@ -121,11 +130,12 @@
121130
<None Include="App.config" />
122131
</ItemGroup>
123132
<ItemGroup>
124-
<Folder Include="Resources\Images\" />
133+
<None Include="Resources\Images\globe.png" />
125134
</ItemGroup>
126135
<ItemGroup>
127136
<Resource Include="globe.ico" />
128137
</ItemGroup>
138+
<ItemGroup />
129139
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
130140
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
131141
Other similar extension points exist, see Microsoft.Common.targets.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Advanced_PortChecker.Classes
2+
{
3+
/// <summary>
4+
/// Represents the content of a ListView item
5+
/// </summary>
6+
public class LvCheck
7+
{
8+
// ReSharper disable once UnusedAutoPropertyAccessor.Global
9+
public string Address { get; set; }
10+
// ReSharper disable once UnusedAutoPropertyAccessor.Global
11+
public int Port { get; set; }
12+
// ReSharper disable once UnusedAutoPropertyAccessor.Global
13+
public string Type { get; set; }
14+
// ReSharper disable once UnusedAutoPropertyAccessor.Global
15+
public string Description { get; set; }
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
3+
namespace Advanced_PortChecker.Classes
4+
{
5+
/// <summary>
6+
/// Represents the content of a scan operation.
7+
/// </summary>
8+
internal class OperationInformation
9+
{
10+
public bool IsCancelled { get; set; }
11+
12+
public IProgress<int> Progress { get; set; }
13+
14+
public IProgress<LvCheck> Preview { get; set; }
15+
}
16+
}

Advanced PortChecker/Classes/PortChecker.cs

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Net.Sockets;
4+
using System.Threading.Tasks;
35

46
namespace Advanced_PortChecker.Classes
57
{
@@ -8,13 +10,116 @@ namespace Advanced_PortChecker.Classes
810
/// </summary>
911
internal static class PortChecker
1012
{
13+
// ReSharper disable once InconsistentNaming
14+
/// <summary>
15+
/// Determine which ports are open on a certain address using a TCP and UDP Client.
16+
/// </summary>
17+
/// <param name="address">The IP address that needs to be scanned.</param>
18+
/// <param name="startPort">The starting point of ports that needs to be scanned.</param>
19+
/// <param name="stopPort">The final port in a range of ports that needs to be scanned.</param>
20+
/// <param name="oi">The operation information regarding this scan.</param>
21+
/// <returns>A list of information regarding the ports and address that was scanned.</returns>
22+
internal static async Task<List<LvCheck>> CheckTCPUDP(string address, int startPort, int stopPort, OperationInformation oi)
23+
{
24+
List<LvCheck> lv = new List<LvCheck>();
25+
await Task.Run(() =>
26+
{
27+
for (int i = startPort; i <= stopPort; i++)
28+
{
29+
if (oi.IsCancelled) return;
30+
31+
lv.AddRange(CheckTCP(address, i, i, oi, false).Result);
32+
lv.AddRange(CheckUDP(address, i, i, oi, false).Result);
33+
34+
oi.Progress.Report(i);
35+
}
36+
});
37+
38+
return lv;
39+
}
40+
41+
// ReSharper disable once InconsistentNaming
42+
/// <summary>
43+
/// Determine which ports are open on a certain address using a TCP Client.
44+
/// </summary>
45+
/// <param name="address">The IP address that needs to be scanned.</param>
46+
/// <param name="startPort">The starting point of ports that needs to be scanned.</param>
47+
/// <param name="stopPort">The final port in a range of ports that needs to be scanned.</param>
48+
/// <param name="oi">The operation information regarding this scan.</param>
49+
/// <param name="reportProgress">A boolean to represent whether this method should report the current progress or not.</param>
50+
/// <returns>A list of information regarding the ports and address that was scanned.</returns>
51+
internal static async Task<List<LvCheck>> CheckTCP(string address, int startPort, int stopPort, OperationInformation oi, bool reportProgress)
52+
{
53+
List<LvCheck> lv = new List<LvCheck>();
54+
await Task.Run(() =>
55+
{
56+
for (int i = startPort; i <= stopPort; i++)
57+
{
58+
if (oi.IsCancelled) return;
59+
60+
// ReSharper disable once UseObjectOrCollectionInitializer
61+
LvCheck check = new LvCheck();
62+
check.Address = address;
63+
check.Port = i;
64+
check.Type = "TCP";
65+
check.Description = IsTcpOpen(address, i) ? "Open" : "Closed";
66+
lv.Add(check);
67+
68+
if (reportProgress)
69+
{
70+
oi.Progress.Report(i);
71+
}
72+
oi.Preview.Report(check);
73+
}
74+
});
75+
return lv;
76+
}
77+
78+
// ReSharper disable once InconsistentNaming
79+
/// <summary>
80+
/// Determine which ports are open on a certain address using an UDP Client.
81+
/// </summary>
82+
/// <param name="address">The IP address that needs to be scanned.</param>
83+
/// <param name="startPort">The starting point of ports that needs to be scanned.</param>
84+
/// <param name="stopPort">The final port in a range of ports that needs to be scanned.</param>
85+
/// <param name="oi">The operation information regarding this scan.</param>
86+
/// <param name="reportProgress">A boolean to represent whether this method should report the current progress or not.</param>
87+
/// <returns>A list of information regarding the ports and address that was scanned.</returns>
88+
internal static async Task<List<LvCheck>> CheckUDP(string address, int startPort, int stopPort, OperationInformation oi, bool reportProgress)
89+
{
90+
List<LvCheck> lv = new List<LvCheck>();
91+
await Task.Run(() =>
92+
{
93+
for (int i = startPort; i <= stopPort; i++)
94+
{
95+
if (oi.IsCancelled) return;
96+
97+
// ReSharper disable once UseObjectOrCollectionInitializer
98+
LvCheck check = new LvCheck();
99+
check.Address = address;
100+
check.Port = i;
101+
check.Type = "UDP";
102+
check.Description = IsUdpOpen(address, i) ? "Open" : "Closed";
103+
lv.Add(check);
104+
105+
if (reportProgress)
106+
{
107+
oi.Progress.Report(i);
108+
}
109+
oi.Preview.Report(check);
110+
}
111+
});
112+
return lv;
113+
}
114+
115+
11116
/// <summary>
12117
/// Determine whether a certain port is open or not on a certain address using a TCP Client.
13118
/// </summary>
14119
/// <param name="address">The IP address that needs to be scanned.</param>
15120
/// <param name="port">The port that needs to be scanned.</param>
16121
/// <returns>Returns true if the port is open for connections.</returns>
17-
internal static bool IsTcpOpen(string address, int port)
122+
private static bool IsTcpOpen(string address, int port)
18123
{
19124
try
20125
{
@@ -37,7 +142,7 @@ internal static bool IsTcpOpen(string address, int port)
37142
/// <param name="address">The IP address that needs to be scanned.</param>
38143
/// <param name="port">The port that needs to be scanned.</param>
39144
/// <returns>Returns true if the port is open for connections.</returns>
40-
internal static bool IsUdpOpen(string address, int port)
145+
private static bool IsUdpOpen(string address, int port)
41146
{
42147
try
43148
{

Advanced PortChecker/Classes/UpdateManager.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ internal class UpdateManager
1313
{
1414

1515
#region Variables
16-
1716
private readonly string _updateUrl;
1817
private Update _update;
19-
2018
#endregion
2119

2220
/// <summary>

Advanced PortChecker/Properties/Resources.Designer.cs

Lines changed: 27 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Advanced PortChecker/Properties/Resources.resx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
4747
mimetype: application/x-microsoft.net.object.binary.base64
4848
value : The object must be serialized with
49-
: System.Serialization.Formatters.Binary.BinaryFormatter
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
5050
: and then encoded with base64 encoding.
5151
5252
mimetype: application/x-microsoft.net.object.soap.base64
@@ -60,6 +60,7 @@
6060
: and then encoded with base64 encoding.
6161
-->
6262
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
6364
<xsd:element name="root" msdata:IsDataSet="true">
6465
<xsd:complexType>
6566
<xsd:choice maxOccurs="unbounded">
@@ -68,9 +69,10 @@
6869
<xsd:sequence>
6970
<xsd:element name="value" type="xsd:string" minOccurs="0" />
7071
</xsd:sequence>
71-
<xsd:attribute name="name" type="xsd:string" />
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
7273
<xsd:attribute name="type" type="xsd:string" />
7374
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
7476
</xsd:complexType>
7577
</xsd:element>
7678
<xsd:element name="assembly">
@@ -85,9 +87,10 @@
8587
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
8688
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
8789
</xsd:sequence>
88-
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
8991
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
9092
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
9194
</xsd:complexType>
9295
</xsd:element>
9396
<xsd:element name="resheader">
@@ -109,9 +112,13 @@
109112
<value>2.0</value>
110113
</resheader>
111114
<resheader name="reader">
112-
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
113116
</resheader>
114117
<resheader name="writer">
115-
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116119
</resheader>
120+
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
121+
<data name="globe" type="System.Resources.ResXFileRef, System.Windows.Forms">
122+
<value>..\Resources\Images\globe.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
123+
</data>
117124
</root>
4.55 KB
Loading

0 commit comments

Comments
 (0)