Tarun
Tarun

Reputation: 63

Network IP blocker in C#

I am new to network programming. I want to create a network blocker. which blocks an IP from the LAN. How is this possible in C#?

Upvotes: 0

Views: 552

Answers (2)

PaulG
PaulG

Reputation: 14021

You would be mimicking what a firewall does, which is insert itself into the tcp stack to monitor all inbound traffic. Installing a firewall is definately the easiest way, otherwise start looking into using a Layered Service Provider

Upvotes: 0

kenny
kenny

Reputation: 22334

In WCF I know this code works

    /// <summary>
    /// Returns the client IP 
    /// </summary>
    public static string ClientIP
    {
        get
        {
            // determine IP address takes < 1ms
            OperationContext context = OperationContext.Current;
            MessageProperties messageProperties = context.IncomingMessageProperties;
            RemoteEndpointMessageProperty endpointProperty =
                messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
            return endpointProperty.Address;
        }
    }

Upvotes: 1

Related Questions