- #!/usr/bin/env python3
- #coding=utf-8
-
- import subprocess
-
-
- port = ":3389"
-
- proc = subprocess.Popen("netstat -n", stdout = subprocess.PIPE)
- try:
- outs, errs = proc.communicate(timeout=15)
- except TimeoutExpired:
- proc.kill()
- outs, errs = proc.communicate()
-
- for n in outs.decode("GBk").split("\n"):
- if n.find(port) > -1:
- print(n.split(":")[0].split(" ")[-1], end="", flush=True)
复制代码
|