Hi

I have C# console application which receives windows username as argument. Based on this username my application needs to find out the IP address where currently this user is logged in so that my console application can invoke WCF service hosted in user's machine.

Can anyone please direct me to correct resource or reply with code if you have came across?

Recommended Answers

All 4 Replies

What have you tried so far?

I cant figure out where you start. I am looking into System.Net classes documentations but does'nt seems to find anything there.

the following code returns me username and machine host name but it will work for the machine the code is running in.

Console.WriteLine("Current Logged UserName: " + Environment.UserName);

            Console.WriteLine("Local Machine Name: " + Environment.MachineName);

            Console.WriteLine("Local Machine Name: " + Dns.GetHostName()); // Dns from System.Net

            IPHostEntry ip = Dns.GetHostEntry(Dns.GetHostName());

            IPAddress[] IPaddr = ip.AddressList;

            for (int i = 0; i < IPaddr.Length; i++)

            { Console.WriteLine("IP Address {0}: {1} ", i, IPaddr[i].ToString()); }

            Console.ReadLine();

Ideally I am looking for some sort of way that a given machine in the network can figure out where another windows user is logged (IP address or machine name)

Well to do so you would need admin permissions to the remote machine, and then you can use WMI to retrieve various peices of data- however to connect to the remote machine you would normally already have a name - which you should be able to do a look up on to get IP..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.