Swiftpack.co - zhaorui/ProcPeek as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by zhaorui.
zhaorui/ProcPeek 1.0.3
๐Ÿ‘€ Find out what TCP ports is opened by a process
โญ๏ธ 1
๐Ÿ•“ 2 weeks ago
.package(url: "https://github.com/zhaorui/ProcPeek.git", from: "1.0.3")


This library can help you to get a list of running processes, get a list of tcp ports opened by the process, and find a process by the tcp port it opened.

Get a list of opened TCP ports of the process.

Just pass the pid of process to the function getLocalTcpPorts(of: pid_t).

let result = getLocalTcpPorts(of: 56605)

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

Get a list of BSD processes

Just use getAllProcess().

for process in getAllProcess() {
    print(process.pid, process.name)

Find process by the TCP port it opened

let process = getProcess(from: 13659)


Stars: 1
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

2 weeks ago

Make ProcessProfile totally public! ๅ…ฌๅผ€ProcessProfile็š„ๆ‰€ๆœ‰ๆˆๅ‘˜๏ผ

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics