0

I have 2 remote machines which can be accessed by a group of machines connected through LAN. If a machine is connects to that remote machine using mstsc, how can we get the name of machine that is connected? Is there any python package to get this data?

Thanks in advance.

Mohan Raj
  • 21
  • 9

1 Answers1

1

You have to run as admin. Following code prints connected machines using mstsc.exe with it's connected port number.

f = subprocess.check_output('netstat -b')
prevLine = ""
for line in f:
    if (line.find("mstsc.exe") !=-1):
        print prevLine.split()[1]
    else:
        prevLine=line

idea is to run netstat with -b option to find all established connections. From output, we can parse for connections using mstsc.

venpa
  • 4,268
  • 21
  • 23