2

Assume there are two systems; System1 and System2.

  • System1 - Windows XP
  • System2 - Linux.

I have installed a WPF application on System1. A user on System2 connects to System1 via a Remote Desktop Connection and launches the WPF application.

In the WPF application, I can get the local IP address and Windows Login Name for System1 using the following code.

private String GetIP()
{
    string strHostName = "";
    strHostName = System.Net.Dns.GetHostName();
    IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
    IPAddress[] addr = ipEntry.AddressList;
    return addr[0].ToString();
}

String WinUserName_withNetwork = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
String WinUserNameOnly = System.Environment.UserName;

My problem is I want the IP address and user name of the user logging in from System2.

What do I need to do in order to get that IP address and user name?

Patrick
  • 17,669
  • 6
  • 70
  • 85
Arun
  • 728
  • 4
  • 16
  • 30
  • See the above http://stackoverflow.com/questions/2046934/how-to-get-ip-address-of-remote-linux-system-using-c-net – kostas ch. Jun 04 '13 at 11:01
  • Wait, *Windows* login name on a Linux system? Would you mind explaining what you mean? (Do you mean user name?) – Patrick Jun 04 '13 at 11:01
  • *"Will launch the WPF application through Remote Connection"*. What is "Remote connection" in this sentence, and how do you launch the application "through" it? – Patrick Jun 04 '13 at 11:08
  • HI Patrick. As unable to install the WPF application in Linux system(System2). So I connected the System1 via Remote Connection and launch the application. But I got the System1 information only. – Arun Jun 04 '13 at 11:22
  • What is Remote Connection? Is it Remote Desktop Connection or VNC? If you launch the applicaiton on System1 via such a program, it is *running on System1* so there's no way to get the information from System2. – Patrick Jun 04 '13 at 11:27
  • Yes. Its running on System1. Application can be launched on System2 via Remote Desktop Connection. – Arun Jun 04 '13 at 11:38

3 Answers3

1

As far as I understand the question you want to know the IP address of the System2 from the System1 computer and the name of the user logged thru the remote connection. Am I right?

Assuming that you can use environment variables to gather this information:

  1. CLIENTNAME: contains the name of the computer connected thru remote desktop.
  2. USERNAME: contains the name of the user logged in.

Hope this helps.

Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207
  • Yupp, this is correct. You might add that you can get the environment variable using [Environment.GetEnvironmentVariable](http://msdn.microsoft.com/en-us/library/77zkk0b6.aspx). – Patrick Jun 04 '13 at 11:58
  • For more advanced terminal service queries, there's a library called [Cassia](https://code.google.com/p/cassia/). There's also a SO question about it; http://stackoverflow.com/questions/14067846/how-can-i-get-the-client-computer-name. – Patrick Jun 04 '13 at 12:06
0

Refer following Code:

IPHostEntry iPAddress = DNS.GetHostByName (HostName);
 IPAddress [] IPAdd = iPAddress.AddressList;

 for (int j = 0; j < IPAdd.Length; j++)
 {
  Console.WriteLine ("IP Address {0}: {1} ", j, IPAdd[j].ToString ());
 }

Can also refer THIS doccument.

Freelancer
  • 9,008
  • 7
  • 42
  • 81
0

Simply open a command prompt / shell and type IPCONFIG

Look for an IP4 address. Quite often you'll see it's "127.0.0.1". Type NSLOOKUP to get the name of the computer.

Hope this helps

baxter
  • 42
  • 2
  • 1
    Why would you launch another application (which might not be consistent between platforms) for fetching the *local* IP address of the computer when you can do it in code? – Patrick Jun 04 '13 at 11:06
  • StackOverflow is about programming. ;-) – CodeCaster Jun 04 '13 at 11:16