Retrieve IP address of Local PC connected to Remote Desktop

0

I am running Windows7 on Local PC and Remote Desktop (don't have admin rights on either).

Say the IP address of my PC is 10.*.4.*1

When I connect to a remote desktop, using netstat I am able to retrieve all the connected IP addresses:

C:\>netstat -n | find "3389" | find "ESTABLISHED"
  TCP    10.*.4.10:3389        10.*.4.*1:50031       ESTABLISHED
  TCP    10.*.4.10:3389        10.*.4.*2:50032       ESTABLISHED
  TCP    10.*.4.10:3389        10.*.4.*3:50033       ESTABLISHED
  TCP    10.*.4.10:3389        10.*.4.*4:50034       ESTABLISHED
  TCP    10.*.4.10:3389        10.*.4.*5:50035       ESTABLISHED

Printing echo %username% I am able to get the account I am connected to on the Remote Desktop.

I would like to echo the IP address of my Local PC with which I am connected to the Remote Desktop.

Igor L.

Posted 2016-05-18T11:44:35.607

Reputation: 103

This is a simillar, yet unrelated question - the first one asks for a list of all connected ip addresses and their current accounts on the remote desktop.

This question asks how to print ip address of the local PC a user is using to connect to the said remote desktop. – Igor L. – 2016-05-18T11:59:23.087

I'll let the mods figure out if it is duplicate or not, because the end result of these two questions seems nearly the same, but for one user instead of all, you want to get IP address and user account of connected user. – acejavelin – 2016-05-18T12:10:59.990

As u wish, but I expect the method of retrieving the data to be different – Igor L. – 2016-05-18T12:17:16.837

1Look at the CLIENTNAME and resolve backwards. – acejavelin – 2016-05-18T12:18:16.570

Answers

2

The CLIENTNAME environment variable holds the name of the client machine. Your IP addresses look like private IPs, so if the client & server are on the same network, you could capture the output of one of these commands

nslookup %CLIENTNAME%
ping %CLIENTNAME%
tracert %CLIENTNAME% | find "Tracing"

Shoeless

Posted 2016-05-18T11:44:35.607

Reputation: 1 172

Thanks a ton, works perfectly. Can u pls check also the linked question?

The architecture of the program I'm trying to write would be simpler if I was able to achieve what is specified in that question.

-> http://superuser.com/questions/1078181/match-account-ipaddress-of-users-connected-to-a-remote-desktop

– Igor L. – 2016-05-18T12:26:03.210

is there a way without using %clientname%? In my situtation this does not work! – user2305193 – 2017-11-17T21:05:45.237