In python is there a cross-platform way of determining what process is listening to a given port?
问题 In linux, I can use lsof -i as in the following function: def FindProcessUsingPort(portnum): import os fp = os.popen("lsof -i :%s" % portnum) lines = fp.readlines() fp.close() pid = None if len(lines) >= 2: pid = int(lines[1].split()[1]) return pid Is there a cross-platform way to figure this out? As a relevant reference, once I know the process id, the psutil library is very nice and lets me determine all sorts of useful process information for it in a cross-platform way. I just can't get