Junior — Middle
What methods can determine which ports on the system are already occupied?
sobes.tech AI
Answer from AI
There are several ways to determine which ports are occupied on the system:
- Using the netstat command:
-
On Linux/macOS:
netstat -tulnShows all listening TCP and UDP ports.
-
On Windows:
netstat -anoShows active connections and process PIDs.
- Using the lsof command (Linux/macOS):
lsof -i -P -n
Shows processes using network ports.
- Using ss (Linux):
ss -tuln
A more modern alternative to netstat.
- Programmatically (for example, in Python), you can try to open a socket on a port to check if it is available.
These methods help identify which ports are occupied and by which processes, useful for configuring network services and resolving conflicts.