1

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.

5
  • Possible duplicate of superuser.com/questions/1078181/… – acejavelin May 18 '16 at 11:53
  • 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. May 18 '16 at 11:59
  • 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 May 18 '16 at 12:10
  • As u wish, but I expect the method of retrieving the data to be different – Igor L. May 18 '16 at 12:17
  • 1
    Look at the CLIENTNAME and resolve backwards. – acejavelin May 18 '16 at 12:18
3

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"
2
  • 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. -> superuser.com/questions/1078181/… – Igor L. May 18 '16 at 12:26
  • is there a way without using %clientname%? In my situtation this does not work! – user2305193 Nov 17 '17 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.