BanningFiltering IPs
Version 5 (Alan McGovern, 10/24/2010 08:22 PM)
1 | 1 | h1. BanningFiltering IPs |
|
---|---|---|---|
2 | 1 | ||
3 | 5 | Alan McGovern | h2. Example 1 |
4 | 5 | Alan McGovern | |
5 | 5 | Alan McGovern | This example shows how to prevent a connection being made to the IPAddress '192.168.0.5' |
6 | 2 | Alan McGovern | |
7 | 3 | Alan McGovern | <pre><code class="java"> |
8 | 1 | private void BanPeer (ClientEngine engine) |
|
9 | 1 | { |
|
10 | 1 | // Hook up a handler to the 'BanPeer' event. This is raised |
|
11 | 1 | // every time a connection is received or an outgoing connection |
|
12 | 1 | // is about to be created. If you wish to close/abort the connection |
|
13 | 1 | // just set "BanPeer" to true. |
|
14 | 1 | engine.ConnectionManager.BanPeer += delegate(object sender, AttemptConnectionEventArgs e) { |
|
15 | 1 | if (e.Peer.ConnectionUri.Host == "192.168.0.5") |
|
16 | 1 | e.BanPeer = true; |
|
17 | 1 | }; |
|
18 | 1 | } |
|
19 | 3 | Alan McGovern | </code></pre> |