Package org.opennms.core.utils
Class InetAddressUtils
- java.lang.Object
-
- org.opennms.core.utils.InetAddressUtils
-
public abstract class InetAddressUtils extends Object
Abstract InetAddressUtils class.
- Version:
- $Id: $
- Author:
- Mathew Brozowski
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInetAddressUtils.AddressType
-
Field Summary
Fields Modifier and Type Field Description static StringINVALID_BRIDGE_ADDRESSstatic StringINVALID_STP_BRIDGE_DESIGNATED_PORTstatic StringINVALID_STP_BRIDGE_IDprotected static DecimalFormatNO_DIGITS_AFTER_DECIMALAlways print at least one digit after the decimal point, and at most three digits after the decimal point.protected static DecimalFormatONE_DIGIT_AFTER_DECIMALPrint no digits after the decimal point (heh, nor a decimal point).static InetAddressONE_TWENTY_SEVENstatic InetAddressTWO_FIFTY_FIVESstatic InetAddressUNPINGABLE_ADDRESSstatic InetAddressUNPINGABLE_ADDRESS_IPV6static InetAddressZEROS
-
Constructor Summary
Constructors Constructor Description InetAddressUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static InetAddressaddr(String ipAddrString)static booleanareSameInetAddress(byte[] leftInetAddr, byte[] rightInetAddr)static InetAddressconvertBigIntegerIntoInetAddress(BigInteger i)static InetAddressconvertCidrToInetAddressV4(int cidr)static InetAddressconvertCidrToInetAddressV6(int cidr)static byte[]decr(byte[] address)static Stringdecr(String address)static BigIntegerdifference(String addr1, String addr2)static BigIntegerdifference(InetAddress addr1, InetAddress addr2)static StringgetBridgeAddressFromStpBridgeId(String bridgeId)static intgetBridgeDesignatedPortNumber(String stpPortDesignatedPort)static StringgetHumanReadableIfSpeed(long ifSpeed)Method used to convert an integer bits-per-second value to a more readable vale using commonly recognized abbreviation for network interface speeds.static InetAddressgetInetAddress(byte[] ipAddrOctets)static InetAddressgetInetAddress(int[] octets, int offset, int length)static InetAddressgetInetAddress(String dottedNotation)getInetAddressstatic InetAddressgetIpAddressByHexString(String ipaddrhexstrng)static InetAddressgetLocalHostAddress()static StringgetLocalHostAddressAsString()static StringgetLocalHostName()static Optional<InetAddress>getLocalLoopbackAddress()static InetAddressgetLowestInetAddress(List<InetAddress> addresses)Given a list of IP addresses, return the lowest as determined by the numeric representation and not the alphanumeric string.static InetAddressgetNetwork(InetAddress ipaddress, InetAddress netmask)static byte[]incr(byte[] address)static Stringincr(String address)static booleaninSameNetwork(InetAddress addr1, InetAddress addr2, InetAddress mask)static booleaninSameScope(InetAddress addr1, InetAddress addr2)static booleanisInetAddressInRange(byte[] addr, byte[] begin, byte[] end)static booleanisInetAddressInRange(byte[] laddr, String beginString, String endString)static booleanisInetAddressInRange(String ipAddr, byte[] begin, byte[] end)static booleanisInetAddressInRange(String addrString, String beginString, String endString)static booleanisValidBridgeAddress(String bridgeAddress)static booleanisValidStpBridgeId(String bridgeId)static booleanisValidStpDesignatedPort(String bridgeDesignatedPort)static StringmacAddressBytesToString(byte[] macAddress)static byte[]macAddressStringToBytes(String macAddress)static Stringnormalize(String ipAddrString)This function is used to ensure that an IP address string is in fully-qualified format without any "::" segments for an IPv6 address.static StringnormalizeMacAddress(String macAddress)static Stringstr(InetAddress addr)static BigIntegertoInteger(InetAddress ipAddress)static byte[]toIpAddrBytes(String dottedNotation)toIpAddrBytesstatic StringtoIpAddrString(byte[] addr)toIpAddrStringstatic StringtoIpAddrString(InetAddress addr)toIpAddrStringstatic StringtoOid(InetAddress addr)static StringtoUrlIpAddress(InetAddress addr)Method that wraps IPv6 addresses in square brackets so that they are parsed correctly by theJMXServiceURLclass.
-
-
-
Field Detail
-
NO_DIGITS_AFTER_DECIMAL
protected static final DecimalFormat NO_DIGITS_AFTER_DECIMAL
Always print at least one digit after the decimal point, and at most three digits after the decimal point.
-
ONE_DIGIT_AFTER_DECIMAL
protected static final DecimalFormat ONE_DIGIT_AFTER_DECIMAL
Print no digits after the decimal point (heh, nor a decimal point).
-
INVALID_BRIDGE_ADDRESS
public static final String INVALID_BRIDGE_ADDRESS
- See Also:
- Constant Field Values
-
INVALID_STP_BRIDGE_ID
public static final String INVALID_STP_BRIDGE_ID
- See Also:
- Constant Field Values
-
INVALID_STP_BRIDGE_DESIGNATED_PORT
public static final String INVALID_STP_BRIDGE_DESIGNATED_PORT
- See Also:
- Constant Field Values
-
UNPINGABLE_ADDRESS
public static final InetAddress UNPINGABLE_ADDRESS
-
UNPINGABLE_ADDRESS_IPV6
public static final InetAddress UNPINGABLE_ADDRESS_IPV6
-
ZEROS
public static final InetAddress ZEROS
-
TWO_FIFTY_FIVES
public static final InetAddress TWO_FIFTY_FIVES
-
ONE_TWENTY_SEVEN
public static final InetAddress ONE_TWENTY_SEVEN
-
-
Method Detail
-
getLocalHostAddress
public static InetAddress getLocalHostAddress()
-
getLocalHostAddressAsString
public static String getLocalHostAddressAsString()
-
getLocalLoopbackAddress
public static Optional<InetAddress> getLocalLoopbackAddress()
-
getLocalHostName
public static String getLocalHostName()
-
incr
public static String incr(String address) throws UnknownHostException
- Throws:
UnknownHostException
-
incr
public static byte[] incr(byte[] address) throws UnknownHostException- Throws:
UnknownHostException
-
decr
public static String decr(String address) throws UnknownHostException
- Throws:
UnknownHostException
-
decr
public static byte[] decr(byte[] address) throws UnknownHostException- Throws:
UnknownHostException
-
getInetAddress
public static InetAddress getInetAddress(int[] octets, int offset, int length)
-
getInetAddress
public static InetAddress getInetAddress(byte[] ipAddrOctets)
-
getInetAddress
public static InetAddress getInetAddress(String dottedNotation)
getInetAddress
- Parameters:
dottedNotation- aStringobject.- Returns:
- a
InetAddressobject.
-
toIpAddrBytes
public static byte[] toIpAddrBytes(String dottedNotation)
toIpAddrBytes
- Parameters:
dottedNotation- aStringobject.- Returns:
- an array of byte.
-
toIpAddrString
public static String toIpAddrString(InetAddress addr)
toIpAddrString
- Parameters:
addr- IP address- Returns:
- a
Stringobject.
-
toIpAddrString
public static String toIpAddrString(byte[] addr)
toIpAddrString
- Parameters:
addr- an array of byte.- Returns:
- a
Stringobject.
-
toUrlIpAddress
public static String toUrlIpAddress(InetAddress addr)
Method that wraps IPv6 addresses in square brackets so that they are parsed correctly by theJMXServiceURLclass.
-
getLowestInetAddress
public static InetAddress getLowestInetAddress(List<InetAddress> addresses)
Given a list of IP addresses, return the lowest as determined by the numeric representation and not the alphanumeric string.- Parameters:
addresses- aListobject.- Returns:
- a
InetAddressobject.
-
difference
public static BigInteger difference(String addr1, String addr2)
-
difference
public static BigInteger difference(InetAddress addr1, InetAddress addr2)
-
isInetAddressInRange
public static boolean isInetAddressInRange(byte[] laddr, String beginString, String endString)
-
isInetAddressInRange
public static boolean isInetAddressInRange(String addrString, String beginString, String endString)
-
areSameInetAddress
public static boolean areSameInetAddress(byte[] leftInetAddr, byte[] rightInetAddr)
-
inSameScope
public static boolean inSameScope(InetAddress addr1, InetAddress addr2)
-
getNetwork
public static InetAddress getNetwork(InetAddress ipaddress, InetAddress netmask)
-
inSameNetwork
public static boolean inSameNetwork(InetAddress addr1, InetAddress addr2, InetAddress mask)
-
isInetAddressInRange
public static boolean isInetAddressInRange(byte[] addr, byte[] begin, byte[] end)
-
isInetAddressInRange
public static boolean isInetAddressInRange(String ipAddr, byte[] begin, byte[] end)
-
convertCidrToInetAddressV4
public static InetAddress convertCidrToInetAddressV4(int cidr)
-
convertCidrToInetAddressV6
public static InetAddress convertCidrToInetAddressV6(int cidr)
-
convertBigIntegerIntoInetAddress
public static InetAddress convertBigIntegerIntoInetAddress(BigInteger i) throws UnknownHostException
- Throws:
UnknownHostException
-
addr
public static InetAddress addr(String ipAddrString)
-
normalize
public static String normalize(String ipAddrString)
This function is used to ensure that an IP address string is in fully-qualified format without any "::" segments for an IPv6 address. FIXME: do we lose
-
str
public static String str(InetAddress addr)
-
toInteger
public static BigInteger toInteger(InetAddress ipAddress)
-
toOid
public static String toOid(InetAddress addr)
-
macAddressStringToBytes
public static byte[] macAddressStringToBytes(String macAddress)
-
macAddressBytesToString
public static String macAddressBytesToString(byte[] macAddress)
-
isValidStpDesignatedPort
public static boolean isValidStpDesignatedPort(String bridgeDesignatedPort)
-
getBridgeDesignatedPortNumber
public static int getBridgeDesignatedPortNumber(String stpPortDesignatedPort)
-
isValidBridgeAddress
public static boolean isValidBridgeAddress(String bridgeAddress)
-
isValidStpBridgeId
public static boolean isValidStpBridgeId(String bridgeId)
-
getBridgeAddressFromStpBridgeId
public static String getBridgeAddressFromStpBridgeId(String bridgeId)
-
getIpAddressByHexString
public static InetAddress getIpAddressByHexString(String ipaddrhexstrng)
-
getHumanReadableIfSpeed
public static String getHumanReadableIfSpeed(long ifSpeed)
Method used to convert an integer bits-per-second value to a more readable vale using commonly recognized abbreviation for network interface speeds. Feel free to expand it as necessary to accommodate different values.- Parameters:
ifSpeed- The bits-per-second value to be converted into a string description- Returns:
- A string representation of the speed ("100 Mbps" for example)
-
-