ProcPeek

main

👀 Find out what TCP ports is opened by a process
zhaorui/ProcPeek

ProcPeek

This library can help you find out what TCP ports is opened by specific process.
Just pass the pid of process to the function getLocalTcpPorts(of: pid_t).

let result = getLocalTcpPorts(of: 56605)
print(result)

It's quite easy to get all the TCP ports opened by one process with a command.

lsof -nP -p <pid> -a -i4TCP

However, if you need to do the job programmatically with Swift in macOS. There's no available documented API to do this.
So I use below functions from libproc just like the command lsof do.

  • proc_pidfdinfo
  • proc_pidinfo

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Wed Nov 09 2022 11:51:54 GMT-1000 (Hawaii-Aleutian Standard Time)