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 class
InetAddressUtils.AddressType
-
Field Summary
Fields Modifier and Type Field Description static String
INVALID_BRIDGE_ADDRESS
static String
INVALID_STP_BRIDGE_DESIGNATED_PORT
static String
INVALID_STP_BRIDGE_ID
protected static DecimalFormat
NO_DIGITS_AFTER_DECIMAL
Always print at least one digit after the decimal point, and at most three digits after the decimal point.protected static DecimalFormat
ONE_DIGIT_AFTER_DECIMAL
Print no digits after the decimal point (heh, nor a decimal point).static InetAddress
ONE_TWENTY_SEVEN
static InetAddress
TWO_FIFTY_FIVES
static InetAddress
UNPINGABLE_ADDRESS
static InetAddress
UNPINGABLE_ADDRESS_IPV6
static InetAddress
ZEROS
-
Constructor Summary
Constructors Constructor Description InetAddressUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static InetAddress
addr(String ipAddrString)
static boolean
areSameInetAddress(byte[] leftInetAddr, byte[] rightInetAddr)
static InetAddress
convertBigIntegerIntoInetAddress(BigInteger i)
static InetAddress
convertCidrToInetAddressV4(int cidr)
static InetAddress
convertCidrToInetAddressV6(int cidr)
static byte[]
decr(byte[] address)
static String
decr(String address)
static BigInteger
difference(String addr1, String addr2)
static BigInteger
difference(InetAddress addr1, InetAddress addr2)
static String
getBridgeAddressFromStpBridgeId(String bridgeId)
static int
getBridgeDesignatedPortNumber(String stpPortDesignatedPort)
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.static InetAddress
getInetAddress(byte[] ipAddrOctets)
static InetAddress
getInetAddress(int[] octets, int offset, int length)
static InetAddress
getInetAddress(String dottedNotation)
getInetAddressstatic InetAddress
getIpAddressByHexString(String ipaddrhexstrng)
static InetAddress
getLocalHostAddress()
static String
getLocalHostAddressAsString()
static String
getLocalHostName()
static Optional<InetAddress>
getLocalLoopbackAddress()
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.static InetAddress
getNetwork(InetAddress ipaddress, InetAddress netmask)
static byte[]
incr(byte[] address)
static String
incr(String address)
static boolean
inSameNetwork(InetAddress addr1, InetAddress addr2, InetAddress mask)
static boolean
inSameScope(InetAddress addr1, InetAddress addr2)
static boolean
isInetAddressInRange(byte[] addr, byte[] begin, byte[] end)
static boolean
isInetAddressInRange(byte[] laddr, String beginString, String endString)
static boolean
isInetAddressInRange(String ipAddr, byte[] begin, byte[] end)
static boolean
isInetAddressInRange(String addrString, String beginString, String endString)
static boolean
isValidBridgeAddress(String bridgeAddress)
static boolean
isValidStpBridgeId(String bridgeId)
static boolean
isValidStpDesignatedPort(String bridgeDesignatedPort)
static String
macAddressBytesToString(byte[] macAddress)
static byte[]
macAddressStringToBytes(String macAddress)
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.static String
normalizeMacAddress(String macAddress)
static String
str(InetAddress addr)
static BigInteger
toInteger(InetAddress ipAddress)
static byte[]
toIpAddrBytes(String dottedNotation)
toIpAddrBytesstatic String
toIpAddrString(byte[] addr)
toIpAddrStringstatic String
toIpAddrString(InetAddress addr)
toIpAddrStringstatic String
toOid(InetAddress addr)
static String
toUrlIpAddress(InetAddress addr)
Method that wraps IPv6 addresses in square brackets so that they are parsed correctly by theJMXServiceURL
class.
-
-
-
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
- aString
object.- Returns:
- a
InetAddress
object.
-
toIpAddrBytes
public static byte[] toIpAddrBytes(String dottedNotation)
toIpAddrBytes
- Parameters:
dottedNotation
- aString
object.- Returns:
- an array of byte.
-
toIpAddrString
public static String toIpAddrString(InetAddress addr)
toIpAddrString
- Parameters:
addr
- IP address- Returns:
- a
String
object.
-
toIpAddrString
public static String toIpAddrString(byte[] addr)
toIpAddrString
- Parameters:
addr
- an array of byte.- Returns:
- a
String
object.
-
toUrlIpAddress
public static String toUrlIpAddress(InetAddress addr)
Method that wraps IPv6 addresses in square brackets so that they are parsed correctly by theJMXServiceURL
class.
-
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
- aList
object.- Returns:
- a
InetAddress
object.
-
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)
-
-