Getting IPs from socket

03/02/2012 18:41 ryuchetval#1
I am currently trying to get the IPs from sockets without calling
Code:
soc.EndAccept(IAsyncResult result)
method to set the socket yet I can't find a way to get the remote adress without this method (which gives errors and blocks login in case of a spam, resulting in incapacity of stopping the spamming IPs)

Is there any alternative to get the adress of the remote user without calling this method?

This is what I use

Code:
    public class Wrapper
    {
        public byte[] buffer;
        public Socket _socket;
        public object connector;
    }
        private void AcceptConnections(IAsyncResult result)
        {
                Wrapper wr = result.AsyncState as Wrapper;
             [B]   [COLOR="Red"]wr._socket = _socket.EndAccept(result);[/COLOR][/B]
                //receive data
                //send data for a new connection
                //accept new connections
        }
Any ideeas are appreciated :)
03/02/2012 20:19 -impulse-#2
You cant get the IP of a connection without it being connected, which requires Accept / EndAccept.
You should use a dictionary and have a maximum amount of connections per IP. Others just disconnect them.
03/02/2012 20:36 ryuchetval#3
Guess I just have to limit the amount of connections per second as spamming would crash the login server. So I think that's why some of the connections couldn't be handled because there were over 100/second coming.
03/02/2012 21:03 -impulse-#4
Quote:
Originally Posted by ryuchetval View Post
Guess I just have to limit the amount of connections per second as spamming would crash the login server. So I think that's why some of the connections couldn't be handled because there were over 100/second coming.
You can always give one thread to the login socket. Create a thread on which you accept socket after socket using socket.Accept().
03/02/2012 21:08 ryuchetval#5
The login is already on one thread but there can't be logged more than 1 accounts simultanously.

Yet by setting a range of time between each login will not totally fix the spam (even if it gets disconnected) I should try to block the IP automatically through Windows Firewall which I have no ideea how to set a rule to block the IP through c# so it sets it on Windows Firewall, guess I'll have to search some more.