public class NetStat extends Object
netstat.
This class is intended for diagnostic purposes; elevated privileges may be required
for full status collection.
powershell must be available via PATH.
nettop and ps must be available via PATH.
lsof and ps must be available via PATH. For
a complete port list, the effective user must be permitted to use sudo to execute
the lsof command without a password.
netstat are shown by lsof --
see lsof FAQ
item 3.29.
| Modifier and Type | Class and Description |
|---|---|
static class |
NetStat.BusyPort
Describes an active TCP port and associates it with the controlling process.
|
static class |
NetStat.HostExecutionException
Thrown to indicate the failure of a host command used in construction of TCP connection status information.
|
| Modifier and Type | Method and Description |
|---|---|
static List<NetStat.BusyPort> |
info()
Gets the list of busy ports on the current host.
|
static void |
main(String[] args)
Writes the list returned by
info() to System.out. |
public static List<NetStat.BusyPort> info()
Note that individual ports may appear more than once in the returned list.
Depending on the source, a port may be listed for both IPv4 and IPv6 uses;
for some applications (e.g. sshd), a port may be shared among multiple
processes.
NetStat.BusyPort instances representing the busy TCP portsRuntimeException - if the busy port information cannot be obtainedCopyright © 2022. All rights reserved.