|
-
Nov 14th, 2002, 03:28 PM
#1
Thread Starter
Junior Member
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.
-
Nov 28th, 2002, 03:32 AM
#2
Lively Member
i would also love to know the answer to this question if anyone knows it?
Thanks
-
Nov 28th, 2002, 03:58 AM
#3
Lively Member
hehehe... youd think this would be a common thing... =\
-
Nov 28th, 2002, 08:29 AM
#4
Frenzied Member
Have the client application send its own Ip address, then have the server recieve it.
Dont gain the world and lose your soul
-
Nov 28th, 2002, 08:31 AM
#5
Thread Starter
Junior Member
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).
-
Nov 28th, 2002, 07:55 PM
#6
Lively Member
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
-
Nov 28th, 2002, 08:10 PM
#7
Lively Member
Ok, the code to find my internal IP is:
VB Code:
Dim ipHost As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName())
Dim ip As System.Net.IPAddress() = ipHost.AddressList
Label1.Text = ip(0).ToString()
How would i get my external IP?
Thanks in advance
-
Nov 28th, 2002, 10:22 PM
#8
Lively Member
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...
-
Nov 28th, 2002, 10:22 PM
#9
Frenzied Member
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
-
Nov 28th, 2002, 10:34 PM
#10
Lively Member
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
-
Nov 29th, 2002, 02:10 AM
#11
Thread Starter
Junior Member
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
-
Nov 29th, 2002, 02:33 AM
#12
Registered User
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.....
-
Nov 29th, 2002, 02:44 AM
#13
Registered User
In the MS example I found they also used IPAddress.Parse as this
IPAddress.Parse(CType(oSock.RemoteEndPoint, IPEndPoint).Adress.ToString)
-
Nov 29th, 2002, 02:47 AM
#14
Thread Starter
Junior Member
Thanks a lot. I'm assuming it will work (can't test it here).
Whatever happened to Winsock1.RemoteHostIP
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|