Results 1 to 14 of 14

Thread: Remote IP from tcpClient object

  1. #1

    Thread Starter
    Junior Member Cakkie's Avatar
    Join Date
    May 2002
    Location
    Olen, Belgium
    Posts
    24

    Question Remote IP from tcpClient object

    Does anyone know how I can get the remove IP address when using a tcpClient object?

    I accept the connection using the AcceptTcpClient of my listener object.

    The tcpClient object does not seem to have any property/method that can give me this information.


    Any help is appreciated.
    Tom Cannaerts
    www.tom.be

  2. #2
    Lively Member
    Join Date
    Nov 2002
    Location
    Perth - Australia
    Posts
    105
    i would also love to know the answer to this question if anyone knows it?

    Thanks

  3. #3
    Lively Member
    Join Date
    Nov 2002
    Location
    Perth - Australia
    Posts
    105
    hehehe... youd think this would be a common thing... =\

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Have the client application send its own Ip address, then have the server recieve it.
    Dont gain the world and lose your soul

  5. #5

    Thread Starter
    Junior Member Cakkie's Avatar
    Join Date
    May 2002
    Location
    Olen, Belgium
    Posts
    24
    The problem is that we are talking about a SMTP server here. This is a protocol which doesn't ask for IP addresses, but needs to record them to add it to the header (just in case it needs to be tracked down).
    Tom Cannaerts
    www.tom.be

  6. #6
    Lively Member
    Join Date
    Nov 2002
    Location
    Perth - Australia
    Posts
    105
    Originally posted by DevGrp
    Have the client application send its own Ip address, then have the server recieve it.
    Thats what i have decided to do... although it would be nice if there was a way to retrieve it

  7. #7
    Lively Member
    Join Date
    Nov 2002
    Location
    Perth - Australia
    Posts
    105
    Ok, the code to find my internal IP is:

    VB Code:
    1. Dim ipHost As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName())
    2.         Dim ip As System.Net.IPAddress() = ipHost.AddressList
    3.         Label1.Text = ip(0).ToString()

    How would i get my external IP?

    Thanks in advance

  8. #8
    Lively Member
    Join Date
    Nov 2002
    Location
    Perth - Australia
    Posts
    105
    Originally posted by DevGrp
    Have the client application send its own Ip address, then have the server recieve it.
    As i get deeper into my project i realise that this isnt a good way to do it...

    it is my opinion that for security reasons the server should be responsible for reading the IP from the client. Seems like a bad idea to trust what the client is telling you the IP is...

  9. #9
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You can use that same code to get your external ip. I take it you are behind a router? I think you have to do a little more work to get the ip from the router. One way you can get it just set up a static webpage to get the ip, have the program connect to the webpage, then grab the ip from the webpage. I've seen it done with other programs before.
    Dont gain the world and lose your soul

  10. #10
    Lively Member
    Join Date
    Nov 2002
    Location
    Perth - Australia
    Posts
    105
    thats not a bad idea... ill try that...

    Surely there is a way to get the IP from the client tho... there must be...
    Cheers for the help dev

  11. #11

    Thread Starter
    Junior Member Cakkie's Avatar
    Join Date
    May 2002
    Location
    Olen, Belgium
    Posts
    24
    Hmm, I'm doing a rewrite of the code using sockets rather than the TCPClient, but I'm facing the same problem. There doesn't seem to be a way to get it directly. I'm getting this problem:
    Code:
    ' This works, it shows something like ipaddress:port
    ListBox1.Items.Add oSock.RemoteEndPoint
    ' this doesn't work, give an error saying that it can't convert EndPoint to String
    strIP = oSock.RemoteEndPoint
    Tom Cannaerts
    www.tom.be

  12. #12
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    Don't you have to do a type convertion to IPEndPoint?

    CType(oSock.RemoteEndPoint, IPEndPoint).Adress.ToString
    CType(oSock.RemoteEndPoint, IPEndPoint).Port.ToString

    Have not tried it myself, thats why I posted it as a question.....

  13. #13
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    In the MS example I found they also used IPAddress.Parse as this

    IPAddress.Parse(CType(oSock.RemoteEndPoint, IPEndPoint).Adress.ToString)

  14. #14

    Thread Starter
    Junior Member Cakkie's Avatar
    Join Date
    May 2002
    Location
    Olen, Belgium
    Posts
    24
    Thanks a lot. I'm assuming it will work (can't test it here).
    Whatever happened to Winsock1.RemoteHostIP
    Tom Cannaerts
    www.tom.be

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width