Re: getting client ip in sock-client on server

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"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

.



Relevant Pages

  • Re: RWW Disconnecting
    ... I understand that remote client encounts following error message when RWW ... I strongly suggest that we rerun the Configure E-mail and Internet ... 825763 How to configure Internet access in Windows Small Business Server ...
    (microsoft.public.windows.server.sbs)
  • Re: Great SWT Program
    ... graphics; one-button mice...all while the machines have tended to be ... the internet are good enough that you can run a modern-as-of-2007 GUI ... * Remote machine has graphical app running that tells the Windows ... network to the client to display a button labeled "foo" at those ...
    (comp.lang.java.programmer)
  • Re: Redirect problems to remote client
    ... sent you a copy of the results file from the client. ... > remote client and redirecting the My Documents folder. ... > - Internet Explorer Maitenance policy processing ... Microsoft is providing this information as a convenience to you. ...
    (microsoft.public.windows.server.sbs)
  • RE: Remote connectivity problems
    ... do you mean you have added a remote client to SBS ... If you have hardware VPN tunnel setup using Linksys or others, ... In this scenario you have to configure the SBS Server computer to enable ...
    (microsoft.public.windows.server.sbs)
  • Re: Mapped Drives over VPN
    ... When the client tries to access a share on the remote machine, ... Microsoft CSS Online Newsgroup Support ... | They have generally two mapped drives. ...
    (microsoft.public.windows.server.sbs)