This commit is contained in:
parent
efb7f1d0d7
commit
3a151ec733
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -72,7 +72,7 @@
|
||||||
"RelativeDocumentMoniker": "Program.cs",
|
"RelativeDocumentMoniker": "Program.cs",
|
||||||
"ToolTip": "C:\\Repos\\BlockIPAddr\\Program.cs",
|
"ToolTip": "C:\\Repos\\BlockIPAddr\\Program.cs",
|
||||||
"RelativeToolTip": "Program.cs",
|
"RelativeToolTip": "Program.cs",
|
||||||
"ViewState": "AgIAAAIAAAAAAAAAAAAqwDYAAAAKAAAAAAAAAA==",
|
"ViewState": "AgIAABgAAAAAAAAAAAAAACoAAAAHAAAAAAAAAA==",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
"WhenOpened": "2025-06-27T16:11:33.579Z",
|
"WhenOpened": "2025-06-27T16:11:33.579Z",
|
||||||
"EditorCaption": ""
|
"EditorCaption": ""
|
||||||
|
@ -87,8 +87,7 @@
|
||||||
"RelativeToolTip": "ClassObj\\ANSI.cs",
|
"RelativeToolTip": "ClassObj\\ANSI.cs",
|
||||||
"ViewState": "AgIAADgAAAAAAAAAAAAAAEoAAAARAAAAAAAAAA==",
|
"ViewState": "AgIAADgAAAAAAAAAAAAAAEoAAAARAAAAAAAAAA==",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
"WhenOpened": "2025-06-30T08:09:46.703Z",
|
"WhenOpened": "2025-06-30T08:09:46.703Z"
|
||||||
"EditorCaption": ""
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@
|
||||||
"RelativeDocumentMoniker": "Program.cs",
|
"RelativeDocumentMoniker": "Program.cs",
|
||||||
"ToolTip": "C:\\Repos\\BlockIPAddr\\Program.cs",
|
"ToolTip": "C:\\Repos\\BlockIPAddr\\Program.cs",
|
||||||
"RelativeToolTip": "Program.cs",
|
"RelativeToolTip": "Program.cs",
|
||||||
"ViewState": "AgIAAAIAAAAAAAAAAAAqwBgAAAAmAAAAAAAAAA==",
|
"ViewState": "AgIAABgAAAAAAAAAAAAAACoAAAAHAAAAAAAAAA==",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
"WhenOpened": "2025-06-27T16:11:33.579Z",
|
"WhenOpened": "2025-06-27T16:11:33.579Z",
|
||||||
"EditorCaption": ""
|
"EditorCaption": ""
|
||||||
|
@ -87,8 +87,7 @@
|
||||||
"RelativeToolTip": "ClassObj\\ANSI.cs",
|
"RelativeToolTip": "ClassObj\\ANSI.cs",
|
||||||
"ViewState": "AgIAADgAAAAAAAAAAAAAAEoAAAARAAAAAAAAAA==",
|
"ViewState": "AgIAADgAAAAAAAAAAAAAAEoAAAARAAAAAAAAAA==",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||||
"WhenOpened": "2025-06-30T08:09:46.703Z",
|
"WhenOpened": "2025-06-30T08:09:46.703Z"
|
||||||
"EditorCaption": ""
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
55
Program.cs
55
Program.cs
|
@ -24,6 +24,10 @@ internal class Program
|
||||||
string rv;
|
string rv;
|
||||||
string color = string.Empty;
|
string color = string.Empty;
|
||||||
|
|
||||||
|
if (!IsValid(arg))
|
||||||
|
Console.WriteLine("{0}ERROR: '{1}{2}{0}' is not a valid IP4 address.{3}", ANSI.fgBrightRed, ANSI.fgBrightWhite, arg.Trim(), ANSI.fgReset);
|
||||||
|
else
|
||||||
|
{
|
||||||
cm.Parameters["@ip4"].Value = arg.Trim();
|
cm.Parameters["@ip4"].Value = arg.Trim();
|
||||||
rv = cm.ExecuteScalar().ToString() ?? string.Empty;
|
rv = cm.ExecuteScalar().ToString() ?? string.Empty;
|
||||||
|
|
||||||
|
@ -32,16 +36,21 @@ internal class Program
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
string ip4 = string.Empty;
|
string? ip4 = string.Empty;
|
||||||
Console.Write("\nEnter an IP Address to block (can include slash-notation) or Enter to Exit: ");
|
Console.Write("\nEnter an IP Address to block (can include slash-notation) or Enter to Exit: ");
|
||||||
ip4 = Console.ReadLine();
|
ip4 = Console.ReadLine();
|
||||||
if (string.IsNullOrWhiteSpace(ip4))
|
if (string.IsNullOrWhiteSpace(ip4))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (!IsValid(ip4))
|
||||||
|
Console.WriteLine("\n{0}ERROR: '{1}{2}{0}' is not a valid IP4 address.{3}", ANSI.fgBrightRed, ANSI.fgBrightWhite, ip4, ANSI.fgReset);
|
||||||
|
else
|
||||||
|
{
|
||||||
using (var cn = new SqlConnection(kmCommonLibsCore.Constants.cnPortal))
|
using (var cn = new SqlConnection(kmCommonLibsCore.Constants.cnPortal))
|
||||||
using (var cm = new SqlCommand("dbo.[BlockIPAddrInFirewall]", cn) { CommandType = System.Data.CommandType.StoredProcedure })
|
using (var cm = new SqlCommand("dbo.[BlockIPAddrInFirewall]", cn) { CommandType = System.Data.CommandType.StoredProcedure })
|
||||||
{
|
{
|
||||||
|
@ -57,4 +66,48 @@ internal class Program
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static internal bool IsValid(string ip)
|
||||||
|
{
|
||||||
|
bool rv = false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (ip.IndexOf('/') > 0) // prevent it from being the first character
|
||||||
|
{
|
||||||
|
string[] part = ip.Split('/');
|
||||||
|
|
||||||
|
if (part.Length != 2)
|
||||||
|
rv = false;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Net.IPAddress? ip4 = null;
|
||||||
|
byte subMask = 0;
|
||||||
|
|
||||||
|
if (System.Net.IPAddress.TryParse(part[0].Trim(), out ip4))
|
||||||
|
rv = true;
|
||||||
|
|
||||||
|
if (rv && byte.TryParse(part[1].Trim(), out subMask))
|
||||||
|
rv = true;
|
||||||
|
else
|
||||||
|
rv = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Net.IPAddress? ip4 = null;
|
||||||
|
if (System.Net.IPAddress.TryParse(ip.Trim(), out ip4))
|
||||||
|
rv = true;
|
||||||
|
else
|
||||||
|
rv = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch //(Exception)
|
||||||
|
{
|
||||||
|
rv = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
|
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
|
||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<History>True|2025-06-30T08:39:28.6629030Z||;True|2025-06-30T04:04:51.2689872-04:00||;True|2025-06-30T04:02:09.8676131-04:00||;True|2025-06-27T12:28:32.0039427-04:00||;True|2025-06-27T12:27:16.4031564-04:00||;True|2025-06-27T12:23:51.7850485-04:00||;True|2025-06-27T12:13:48.5390689-04:00||;True|2025-06-27T12:12:59.9985493-04:00||;</History>
|
<History>True|2025-06-30T08:59:56.4591901Z||;True|2025-06-30T04:39:28.6629030-04:00||;True|2025-06-30T04:04:51.2689872-04:00||;True|2025-06-30T04:02:09.8676131-04:00||;True|2025-06-27T12:28:32.0039427-04:00||;True|2025-06-27T12:27:16.4031564-04:00||;True|2025-06-27T12:23:51.7850485-04:00||;True|2025-06-27T12:13:48.5390689-04:00||;True|2025-06-27T12:12:59.9985493-04:00||;</History>
|
||||||
<LastFailureDetails />
|
<LastFailureDetails />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -14,7 +14,7 @@ using System.Reflection;
|
||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("BlockIPAddr")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("BlockIPAddr")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+76d5541e7e2e23eff1f7874ec3c40a46ef7e1f8d")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+efb7f1d0d738f43b349531543f29c49f3aeb5470")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("BlockIPAddr")]
|
[assembly: System.Reflection.AssemblyProductAttribute("BlockIPAddr")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("BlockIPAddr")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("BlockIPAddr")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
61c37c42ee97e4459c046c73f3178cb9717e64e39648654751cd12b3dad0d28b
|
c84dbfe279a9cd8c0873c77e2b29092480d38fd5ce8820b0e4f176205c0421bf
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -14,7 +14,7 @@ using System.Reflection;
|
||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("BlockIPAddr")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("BlockIPAddr")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+76d5541e7e2e23eff1f7874ec3c40a46ef7e1f8d")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+efb7f1d0d738f43b349531543f29c49f3aeb5470")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("BlockIPAddr")]
|
[assembly: System.Reflection.AssemblyProductAttribute("BlockIPAddr")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("BlockIPAddr")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("BlockIPAddr")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
87dc558f82f5265012bd9142dc02bd8e54fbd91b8009a10a518788f869939f12
|
500f127d0ffbefeb4cde081852291a6f06e934c34e9f3103da7408e73bb57605
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -14,7 +14,7 @@ using System.Reflection;
|
||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("BlockIPAddr")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("BlockIPAddr")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+76d5541e7e2e23eff1f7874ec3c40a46ef7e1f8d")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+efb7f1d0d738f43b349531543f29c49f3aeb5470")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("BlockIPAddr")]
|
[assembly: System.Reflection.AssemblyProductAttribute("BlockIPAddr")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("BlockIPAddr")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("BlockIPAddr")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
87dc558f82f5265012bd9142dc02bd8e54fbd91b8009a10a518788f869939f12
|
500f127d0ffbefeb4cde081852291a6f06e934c34e9f3103da7408e73bb57605
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue