Enum NetStat.Platform
- All Implemented Interfaces:
Serializable,Comparable<NetStat.Platform>,java.lang.constant.Constable
- Enclosing class:
- NetStat
Specifies the platform-dependent support for obtaining
netstat-like information.-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic NetStat.PlatformGets thePlatformconstant for the current operating system.private static List<NetStat.BusyPort>mergeCommands(List<NetStat.BusyPort> busyPorts) Creates an updatedBusyPortlist merging in a more complete command string from thepscommand.abstract List<NetStat.BusyPort>netstat()Gets the list of TCP connections joined with information about the process that owns each connection.abstract List<NetStat.BusyPort>netstat(int port) Gets the list of TCP connections for a single local port joined with information about the process that owns each connection.private static String[]prepareCommand(String[] commandTemplate, Object... args) Prepares a command array usingString.formatto substitute arguments.private static <T> List<T>static NetStat.PlatformReturns the enum constant of this type with the specified name.static NetStat.Platform[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
WINDOWS
Handles processing for Windows variants. For successful operation,powershellmust be available viaPATH. -
MAC
Handles processing for Mac OS X. This uses thenettopcommand in single-sample mode and augments the output with apscommand. Unlikelsof,nettopdoes not require elevated privileges to observe the open ports of processes opened by "other" users. -
LINUX
Handles processing for Linux variants. This uses thelsoffor discovering open ports and augments thelsofoutput with output fromps.lsofrequires elevated privileges to see all ports and executed under the control ofsudowith the password prompt suppressed.On Linux implementations which have
sudoandlsofbut do not have full representation of the network stack in the/procfilesystem, thenetstat()method will return an empty list.
-
-
Field Details
-
osPlatform
-
PS_COMMAND
-
PS_PATTERN
-
-
Constructor Details
-
Platform
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
netstat
Gets the list of TCP connections joined with information about the process that owns each connection. Administrator privileges may be required for complete output.- Returns:
- a list of
BusyPortinstances describing the active ports; this list may include both IPv4 and IPv6 connections - Throws:
NetStat.HostExecutionException- if there was a failure in obtaining the TCP connections or host processes lists
-
netstat
Gets the list of TCP connections for a single local port joined with information about the process that owns each connection. Administrator privileges may be required for complete output.- Parameters:
port- the target port- Returns:
- a list of
BusyPortinstances describing the active connections forport; this list may include both IPv4 and IPv6 connections - Throws:
NetStat.HostExecutionException- if there was a failure in obtaining the TCP connections or host processes lists
-
getPlatform
Gets thePlatformconstant for the current operating system.- Returns:
- the current
Platformconstant - Throws:
EnumConstantNotPresentException- if the current operating system is not supported
-
mergeCommands
private static List<NetStat.BusyPort> mergeCommands(List<NetStat.BusyPort> busyPorts) throws NetStat.HostExecutionException Creates an updatedBusyPortlist merging in a more complete command string from thepscommand.- Parameters:
busyPorts- a list ofBusyPortinstances to update- Returns:
- a new list of updated
BusyPortinstances - Throws:
NetStat.HostExecutionException- if an error is raised trying to run thepscommand
-
runCommand
private static <T> List<T> runCommand(String[] command, Function<Stream<String>, List<T>> conversion) throws NetStat.HostExecutionException- Throws:
NetStat.HostExecutionException
-
prepareCommand
Prepares a command array usingString.formatto substitute arguments. If the argument list contains more than one argument,commandTemplateshould use format specifiers using the argument index form.- Parameters:
commandTemplate- the array composing the command to prepareargs- the arguments to substitute into the command array strings- Returns:
- the prepared command array
-