public class NetStat
extends java.lang.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 java.util.List<NetStat.BusyPort> |
info()
Gets the list of busy ports on the current host.
|
static java.util.List<NetStat.BusyPort> |
info(int port)
Gets the list of busy ports associated with a single local port.
|
static void |
main(java.lang.String[] args)
Writes the list returned by
info() to System.out. |
public static java.util.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 portsjava.lang.RuntimeException - if the busy port information cannot be obtainedpublic static java.util.List<NetStat.BusyPort> info(int port)
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.
port - the target portNetStat.BusyPort instances representing the busy TCP portsjava.lang.IllegalArgumentException - if port is not a valid port numberjava.lang.RuntimeException - if the busy port information cannot be obtainedpublic static void main(java.lang.String[] args)
info() to System.out.args - zero or more port numbers to checkCopyright © 2022. All rights reserved.