Re: getting client ip in sock-client on server
- From: "Goran Sliskovic" <gsliskov@xxxxxxxxx>
- Date: Sat, 21 Jan 2006 21:34:16 +0100
"Ankit Aneja" <efextra@xxxxxxxxxxxxxxxxx> wrote in message news:ebf49hkHGHA.2696@xxxxxxxxxxxxxxxxxxxxxxx
can u give me some sample code how i can get remote ip without changing much of my present code
....
Hi,
Here it is: <CUT> using System; using System.Reflection; using System.Reflection.Emit;
using System.Net; using System.Net.Sockets;
namespace ConsoleApplication1 {
public class Test {
public static void Main() {
TcpListener tcpListener = new TcpListener(IPAddress.Any, 10000);
tcpListener.Start();
TcpClient client = tcpListener.AcceptTcpClient();
Type tcpClientType = typeof(TcpClient);
//get value of protected TCPClient property Client that holds socket...
Socket clientSocket = (Socket)tcpClientType.InvokeMember("Client", BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Instance , null, client, null);
//socket RemoteEndpoint is address of connected tcpClinet...
IPEndPoint endPoint = (IPEndPoint) clientSocket.RemoteEndPoint;
string remotAddr = endPoint.Address.ToString();
}
}
}
</CUT>
Please note that such thing is considered bad practice and potentialy dangerous. No guarantees.
Regards, Goran
.
- References:
- getting client ip in sock-client on server
- From: Ankit Aneja
- Re: getting client ip in sock-client on server
- From: Marko Becirevic
- Re: getting client ip in sock-client on server
- From: Ankit Aneja
- Re: getting client ip in sock-client on server
- From: Goran Sliskovic
- Re: getting client ip in sock-client on server
- From: Ankit Aneja
- Re: getting client ip in sock-client on server
- From: "TerryFei"
- getting client ip in sock-client on server
- Prev by Date: Re: Getting the COM IDataObject interface from the DataObject class
- Next by Date: getting another window's handle from a mouse click
- Previous by thread: Re: getting client ip in sock-client on server
- Next by thread: Re: getting client ip in sock-client on server
- Index(es):
Relevant Pages
|