Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何通过C检测Windows Server上的VPN登录_C#_Vpn - Fatal编程技术网

C# 如何通过C检测Windows Server上的VPN登录

C# 如何通过C检测Windows Server上的VPN登录,c#,vpn,C#,Vpn,如何在Windows Server上编写VPN日志的侦听器?我想写一个应用程序,每当有人VPN进入我的Windows服务器时都会提醒我。我能够编写侦听服务器登录的代码。因此,我想编写如下代码,但对于VPN登录: protected override void OnSessionChange(SessionChangeDescription e) { switch (e.Reason) { c

如何在Windows Server上编写VPN日志的侦听器?我想写一个应用程序,每当有人VPN进入我的Windows服务器时都会提醒我。我能够编写侦听服务器登录的代码。因此,我想编写如下代码,但对于VPN登录:

protected override void OnSessionChange(SessionChangeDescription e)
{ 
                switch (e.Reason)
                {
                    case SessionChangeReason.SessionLock:
                                    break;
                    case SessionChangeReason.SessionLogon:
                           break;
                    case SessionChangeReason.SessionUnlock:
                           break;
                    case SessionChangeReason.ConsoleConnect:
                           break;
                    case SessionChangeReason.ConsoleDisconnect:
                          break;

                    case SessionChangeReason.RemoteConnect:
                         break;

                    case SessionChangeReason.RemoteDisconnect:
                         break;
                }

}

如果您使用的是Windows VPN,这里有两个选项可以使用

默认情况下,日志文件保存在%windir%\system32\Logfiles\RRAS中。您可以在那里解析日志文件。每个会话将有4行:用户名、登录时间和IP地址。注销将是发生时的第四个条目。您可以使用RRAS MMC>属性>日志记录更改日志记录目录

另一个选项是,您可以使用并查找日志设置为Security,源设置为RemoteAccess的条目。查看其他属性的文档以确定所需的属性

您可以枚举所有条目:

EventLog log = EventLog.GetEventLogs()
    .First(o => o.Log == "Security" && o.Source=="RemoteAccess");

foreach (EventLogEntry entry in log.Entries)
{
    Console.WriteLine("\tEntry: " + entry.Message);
}
(可选)您可以添加用于实时监视的事件处理程序:

private void Log_EntryWritten(object sender, EntryWrittenEventArgs e)
{
    string message = e.Entry.Message;
    Console.WriteLine(message);
}


public void MonitorVPNLogs()
{
    EventLog log = EventLog.GetEventLogs()
        .First(o => o.Log == "Security" && o.Source=="RemoteAccess");

    log.EnableRaisingEvents = true;
    log.EntryWritten += Log_EntryWritten;
}

什么是VPN服务?你试过什么?这个服务有API吗?@AlexanderHiggins你能详细解释一下VPN服务是什么意思吗?我正在使用Peap方法来保护我的VPN。我搜索了整个网络,我找不到任何关于VPN侦听器的文章,他们只讨论验证VPN登录详细信息,而没有侦听服务器上的VPN连接。是否使用radius服务器、Cisco VPN或内置Windows server VPN或???使用Windows VPN如果您已实施安全审核日志记录,您可能可以读取事件日志。我使用的是内置Windows Server VPN。我将阅读事件日志。谢谢。我在实现你的代码时遇到了问题。我通过使用FileSystemWatcher库修复了这个问题。该库监视vpn日志文件,并在文件更改时向我们发送通知。我的第一个建议当时奏效了。很高兴看到你找到了一个有效的解决方案。当然。非常感谢。