private static void EventSink_SocketConnect(SocketConnectEventArgs e) { try { IPAddress ip = ((IPEndPoint)e.Socket.RemoteEndPoint).Address; if (Firewall.IsBlocked(ip)) { Console.WriteLine("Client: {0}: Firewall blocked connection attempt.", ip); e.AllowConnection = false; return; } else if (IPLimiter.SocketBlock && !IPLimiter.Verify(ip)) { Console.WriteLine("Client: {0}: Past IP limit threshold", ip); using (StreamWriter op = new StreamWriter("ipLimits.log", true)) op.WriteLine("{0}\tPast IP limit threshold\t{1}", ip, DateTime.UtcNow); e.AllowConnection = false; return; } } catch { e.AllowConnection = false; } }
private static void EventSink_SocketConnect(SocketConnectEventArgs e) { try { var ip = (e.Connection.RemoteEndPoint as IPEndPoint)?.Address; if (Firewall.IsBlocked(ip)) { logger.Information("Client: {IP}: Firewall blocked connection attempt.", ip); e.AllowConnection = false; return; } if (IPLimiter.SocketBlock && !IPLimiter.Verify(ip)) { logger.Warning("Client: {IP}: Past IP limit threshold", ip); using (var op = new StreamWriter("ipLimits.log", true)) { op.WriteLine("{0}\tPast IP limit threshold\t{1}", ip, Core.Now); } e.AllowConnection = false; } } catch { e.AllowConnection = false; } }
private static void EventSink_SocketConnect(SocketConnectEventArgs e) { try { IPAddress ip = ((IPEndPoint)e.Socket.RemoteEndPoint).Address; if (Firewall.IsBlocked(ip)) { log.ErrorFormat("Client: {0}: Firewall blocked connection attempt.", ip); e.AllowConnection = false; return; } else if (IPLimiter.SocketBlock && !IPLimiter.Verify(ip)) { log.ErrorFormat("Client: {0}: Past IP limit threshold", ip); e.AllowConnection = false; return; } } catch { e.AllowConnection = false; } }
private static void EventSink_SocketConnect(SocketConnectEventArgs e) { try { IPAddress ip = ((IPEndPoint)e.Socket.RemoteEndPoint).Address; if (Firewall.IsBlocked(ip)) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine("Client: {0}: Firewall blocked connection attempt.", ip); Utility.PopColor(); e.AllowConnection = false; return; } else if (IPLimiter.SocketBlock && !IPLimiter.Verify(ip)) { Utility.PushColor(ConsoleColor.Red); Console.WriteLine("Client: {0}: Past IP limit threshold", ip); Utility.PopColor(); using (StreamWriter op = new StreamWriter("ipLimits.log", true)) op.WriteLine("{0}\tPast IP limit threshold\t{1}", ip, DateTime.UtcNow); e.AllowConnection = false; return; } } catch (Exception ex) { Diagnostics.ExceptionLogging.LogException(ex); e.AllowConnection = false; } }
private static void OnSocketConnect(SocketConnectEventArgs e) { try { IPAddress ip = ((IPEndPoint)e.Socket.RemoteEndPoint).Address; if (Firewall.IsBlocked(ip)) { Console.WriteLine("Client: {0}: Firewall blocked connection attempt.", ip); e.AllowConnection = false; return; } if (!IPLimiter.SocketBlock || IPLimiter.Verify(ip)) { return; } LoggingCustom.Log( "LOG_IPLimits.log", String.Format("{0}\tPast IP limit threshold\t{1}", ip, DateTime.Now.ToSimpleString("t d-m-y N"))); Console.WriteLine("Client: {0}: Past IP limit threshold", ip); e.AllowConnection = false; } catch { e.AllowConnection = false; } }