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.

4

1 回答 1

1

您必须以管理员身份运行。以下代码使用 mstsc.exe 及其连接的端口号打印连接的机器。

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

想法是使用 -b 选项运行 netstat 以查找所有已建立的连接。从输出中,我们可以使用 mstsc 解析连接。

于 2014-03-18T13:36:47.730 回答