TcpListener listening to local network devices

54 Views Asked by At

Not sure that I am actually using the right terms here.

I'm writing a simple server in C# and using a TcpListener to listen to connection requests. I want to allow only connection requests from (1) my own pc and (2) devices that are connected to the same router as my PC.

Is there anything that already does this or will I have to implement this on my own? (I did not manage to find anything implemented already.)

If I have to implement this on my own, one approach is first calculating valid IPs and then listen on these (and perhaps update the listener every once in a while when devices connect and disconnect from the network). Another approach is simply listening to IPAddress.Any, and when the listener returns a new TcpClient just verify its IP (and perhaps close it if it is not valid).

I'm leaning towards method two, as it seems much simpler to me. I guess this is susceptible to some form of attacks, however.

What is the right way to go here?

0

There are 0 best solutions below