Client IP Address


Client IP Address

Hi

I am using VB.net to run a Server Client application through TCP/IP I managed to connect and transmit data. One probel I am finding is that I need to get the IP address of the client while accepting and compare it to a list in the database. If the IP address is not in the database, the connection will be terminated.

Can someone pls show me how to red the Client's IP address.

Thank you all


Answer this question

Client IP Address

  • Dukeboss

    hi,

    i'm searching for the same thing and i found this in other thread

    http://www.developerfusion.co.uk/show/3918/

    best regards



  • Wurschti

    Once you accept the TCPClient
    use
    TcpClient.Client.RemoteEndPoint.Address

    if you are using Sockets use Socket.RemoteEndPoint.Address



  • pavlo_ua

    Hi,

    With .NET's socket class I think a standard way to "filter" connections would be to initially accept all incoming connections by calling the .Accept() method on the listening socket, and then to close any of the resulting sockets where the IP Address as found it that socket's RemoteEndPoint isn't in your list. e.g.:

    > Dim connection as Socket=listeningSocket.Accept()
    >
    > If  AddressInDatabase( _
    >         CType(connection.RemoteEndPoint, IPEndPoint).Address) Then
    >    HandleNewConnection(connection)
    > else
    >    connection.Close()
    > End If

    Note that the Address property returns an object of type System.Net.IPAddress, not a string.


  • SVK

    Sorry but none of the suggestion above worked. (I'm still new to using Sockets and need some help), and if can someone give me a link to a good tutorial on TCP/IP with .NEt it would be really appreceated.

    Thank YouBig Smile

  • Nick Poulis

    Durga mentioned you can access TcpClient.Client.RemoteEndPoint.Address.  This does return an IPAddress instance; however, the Equals(object) method on IPAddress is overriden and can be used to compare if two IPAddress objects represent the same IPAddress.

  • aldone

    Lets us know what you tried and what did not work.
    For TCP/IP using .NET.
    http://search.msn.com/results.aspx q=TCP%2FIP+C%23+tutorial&FORM=QBHP



  • Client IP Address