Skip to content

Commit

Permalink
[Powershell] Update publish setting for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
KuoAnn committed Apr 19, 2023
1 parent 4f7aec2 commit ebb0056
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
3 changes: 1 addition & 2 deletions AutoBlockIP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows10.0.17763.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PlatformTarget>x64</PlatformTarget>
<SatelliteResourceLanguages>en;zh-TW</SatelliteResourceLanguages>
<VersionSuffix>1.$([System.DateTime]::Now.ToString(yy)).$([System.DateTime]::Now.ToString(MMdd)).$([System.DateTime]::Now.ToString(HHmm))</VersionSuffix>
<AssemblyVersion Condition=" '$(VersionSuffix)' == '' ">9.9.9.9</AssemblyVersion>
Expand Down
8 changes: 5 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ private static void Main(string[] args)
bufferBaseFilename: @"Logs\Seq-BlockIp")
.CreateLogger();

var assemblyVersion = Assembly.GetEntryAssembly()?.GetName().Version;

try
{
Log.Warning("[AutoBlockIP] START");
Log.Warning("[AutoBlockIP][{assemblyVersion}] START");
var ips = GetSuspiciousIps();
if (ips.Count() > 0)
{
Expand Down Expand Up @@ -59,7 +61,7 @@ private static void Main(string[] args)
}
else
{
logMessage.AppendLine($"\nUnextract IP");
Log.Warning($"\nUnextract IP");
}
}
catch (Exception ex)
Expand All @@ -68,7 +70,7 @@ private static void Main(string[] args)
}
finally
{
Log.Warning("[AutoBlockIP] Done\n" + logMessage.ToString());
Log.Warning("[AutoBlockIP][{assemblyVersion}] END", assemblyVersion);
Log.CloseAndFlush();
#if DEBUG
Console.ReadKey();
Expand Down
5 changes: 1 addition & 4 deletions Properties/PublishProfiles/FolderProfile.pubxml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishDir>bin\Publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net6.0-windows10.0.17763.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<SelfContained>false</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
</PropertyGroup>
</Project>
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This Batch Will Auto block suspicious IP from windows event log.
2. Configure the firewall through the power shell
3. Log windows event

### Event log datas - 4625
### Event-4625 log datas
``` xml
<Data Name="SubjectUserSid">S-1-0-0</Data>
<Data Name="SubjectUserName">-</Data>
Expand Down Expand Up @@ -80,5 +80,10 @@ if ($all_ips.Contains($ip)){
#Remove-IpAddressToFirewallRule -RuleName "Hacer" -Ip "161.162.163.164"
```
## Memo
Can't Publish wtih Single File or you will get error below:
> The type initializer for 'System.Management.Automation.ExperimentalFeature' threw an exception.
## Ref
> https://dotblogs.com.tw/jamesfu/2022/09/13/PowerShell_Block_IP_Address

0 comments on commit ebb0056

Please sign in to comment.