嘿,我正在为自己的Windows Server编写RDP Bruteforce Protection程序,甚至在更改RDP端口后也会受到攻击:/
但是我已经受登录控制台的困扰,当几乎同时发生2次攻击时,控制台输出“重叠”,如:
显示我基本操作的简约代码:
watcher.EventRecordWritten +=
new EventHandler<EventRecordWrittenEventArgs>(EventLogEventRead);
public static async void EventLogEventRead(object obj,
EventRecordWrittenEventArgs arg)
{
if (arg.EventRecord != null)
{
string IP = GetIPFromRecord(arg.EventRecord)
var json = await new HttpClient().GetStringAsync("https://api.ipgeolocationapi.com/geolocate/" + IP);
var jsonDeserialized = new JavaScriptSerializer().Deserialize<dynamic>(json);
string country = jsonDeserialized["name"];
Console.WriteLine("IP:\t" + IP);
Console.WriteLine("Country:\t" + country);
}
else
{
Console.WriteLine("The event instance was null.");
}
}
完整代码(无错误消息类):Pastebin
那么解决这种问题的最优雅的方法是什么?
Console.WriteLine()
。您需要准备整个输出主体并将其立即写入控制台。