public class NetworkUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
IN_ADDR_ANY
A string containing the "any" local address.
|
static java.lang.String |
IN4_ADDR_ANY
A string containing the "any" local address for IPv4.
|
static java.lang.String |
IN6_ADDR_ANY
A string containing the "any" local address for IPv6.
|
static int |
MAX_PORT_NUMBER
The maximum int value that could correspond to a port number.
|
static int |
MIN_PORT_NUMBER
The minimum int value that could correspond to a port number bindable
by the SIP Communicator.
|
static boolean |
PDEFAULT_DNS_ALWAYS_ABSOLUTE
Default value of
PNAME_DNS_ALWAYS_ABSOLUTE . |
static java.lang.String |
PNAME_DNS_ALWAYS_ABSOLUTE
The name of the boolean property that defines whether all domain names
looked up from Jitsi should be treated as absolute.
|
Constructor and Description |
---|
NetworkUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
clearDefaultDNSCache()
Clears the default DNS cache.
|
static int |
compareDnsNames(java.lang.String dns1,
java.lang.String dns2)
Compares two DNS names against each other.
|
static java.net.InetSocketAddress |
getAAAARecord(java.lang.String domain,
int port)
Returns array of hosts from the AAAA record of the specified domain.
|
static java.net.InetSocketAddress[] |
getAandAAAARecords(java.lang.String domain,
int port)
Returns array of hosts from the A and AAAA records of the specified
domain.
|
static java.net.InetSocketAddress |
getARecord(java.lang.String domain,
int port)
Returns array of hosts from the A record of the specified domain.
|
static java.net.InetAddress |
getInetAddress(java.lang.String hostAddress)
Creates an InetAddress from the specified hostAddress.
|
static java.lang.String[][] |
getNAPTRRecords(java.lang.String domain)
Makes a NAPTR query and returns the result.
|
static int |
getRandomPortNumber()
Returns a random local port number that user applications could bind to.
|
static int |
getRandomPortNumber(int min,
int max)
Returns a random local port number in the interval [min, max].
|
static SRVRecord |
getSRVRecord(java.lang.String service,
java.lang.String proto,
java.lang.String domain)
Returns an InetSocketAddress representing the first SRV
record available for the specified domain or null if there are
not SRV records for domain.
|
static SRVRecord[] |
getSRVRecords(java.lang.String domain)
Returns array of hosts from the SRV record of the specified domain.
|
static SRVRecord[] |
getSRVRecords(java.lang.String domain,
boolean useDNSCache)
Returns array of hosts from the SRV record of the specified domain.
|
static SRVRecord[] |
getSRVRecords(java.lang.String service,
java.lang.String proto,
java.lang.String domain)
Returns an InetSocketAddress representing the first SRV
record available for the specified domain or null if there are
not SRV records for domain.
|
static SRVRecord[] |
getSRVRecords(java.lang.String service,
java.lang.String proto,
java.lang.String domain,
boolean useDNSCache)
Returns an InetSocketAddress representing the first SRV
record available for the specified domain or null if there are
not SRV records for domain.
|
static boolean |
isIPv4Address(java.lang.String address)
Verifies whether address could be an IPv4 address string.
|
static boolean |
isIPv6Address(java.lang.String address)
Verifies whether address could be an IPv6 address string.
|
static boolean |
isValidIPAddress(java.lang.String address)
Checks whether address is a valid IP address string.
|
static boolean |
isValidPortNumber(int port)
Determines whether port is a valid port number bindable by an
application (i.e.
|
static boolean |
isWindowsAutoConfiguredIPv4Address(java.net.InetAddress add)
Determines whether the address is the result of windows auto configuration.
|
static byte[] |
mappedIPv4ToRealIPv4(byte[] addr)
Returns an IPv4 address matching the one mapped in the IPv6
addr.
|
static byte[] |
strToIPv4(java.lang.String ipv4AddrStr)
Creates a byte array containing the specified ipv4AddStr.
|
static byte[] |
strToIPv6(java.lang.String ipv6AddrStr)
Creates a byte array containing the specified ipv6AddStr.
|
public static final java.lang.String IN6_ADDR_ANY
public static final java.lang.String IN4_ADDR_ANY
public static final java.lang.String IN_ADDR_ANY
public static final int MAX_PORT_NUMBER
public static final int MIN_PORT_NUMBER
public static final java.lang.String PNAME_DNS_ALWAYS_ABSOLUTE
public static final boolean PDEFAULT_DNS_ALWAYS_ABSOLUTE
PNAME_DNS_ALWAYS_ABSOLUTE
.public static boolean isWindowsAutoConfiguredIPv4Address(java.net.InetAddress add)
add
- the address to inspectpublic static int getRandomPortNumber()
public static int getRandomPortNumber(int min, int max)
min
- the minimum allowed value for the returned port number.max
- the maximum allowed value for the returned port number.public static boolean isIPv4Address(java.lang.String address)
address
- the String that we'd like to determine as an IPv4 address.public static boolean isIPv6Address(java.lang.String address)
address
- the String that we'd like to determine as an IPv6 address.public static boolean isValidIPAddress(java.lang.String address)
address
- the address that we'd like to checkpublic static byte[] strToIPv4(java.lang.String ipv4AddrStr)
ipv4AddrStr
- a String containing an IPv4 address.public static byte[] strToIPv6(java.lang.String ipv6AddrStr)
ipv6AddrStr
- a String containing an IPv6 address.public static SRVRecord[] getSRVRecords(java.lang.String domain) throws java.text.ParseException, DnssecException
domain
- the name of the domain we'd like to resolve (_proto._tcp
included).java.text.ParseException
- if domain is not a valid domain name.DnssecException
- when a DNSSEC validation failure occurred.public static SRVRecord[] getSRVRecords(java.lang.String domain, boolean useDNSCache) throws java.text.ParseException, DnssecException
domain
- the name of the domain we'd like to resolve (_proto._tcp
included).useDNSCache
- Tells the lookup to use (or not) the DNS cache to
resolve the domain requested. i.e. it is useful to disable the DNS cache
when doing requests for testing DNS connectivity.java.text.ParseException
- if domain is not a valid domain name.DnssecException
- when a DNSSEC validation failure occurred.public static SRVRecord getSRVRecord(java.lang.String service, java.lang.String proto, java.lang.String domain) throws java.text.ParseException, DnssecException
domain
- the name of the domain we'd like to resolve.service
- the service that we are trying to get a record for.proto
- the protocol that we'd like service on.java.text.ParseException
- if domain is not a valid domain name.DnssecException
- when a DNSSEC validation failure occurred.public static SRVRecord[] getSRVRecords(java.lang.String service, java.lang.String proto, java.lang.String domain) throws java.text.ParseException, DnssecException
domain
- the name of the domain we'd like to resolve.service
- the service that we are trying to get a record for.proto
- the protocol that we'd like service on.java.text.ParseException
- if domain is not a valid domain name.DnssecException
- when a DNSSEC validation failure occurred.public static SRVRecord[] getSRVRecords(java.lang.String service, java.lang.String proto, java.lang.String domain, boolean useDNSCache) throws java.text.ParseException, DnssecException
domain
- the name of the domain we'd like to resolve.service
- the service that we are trying to get a record for.proto
- the protocol that we'd like service on.useDNSCache
- Tells the lookup to use (or not) the DNS cache to
resolve the domain requested. i.e. it is useful to disable the DNS cache
when doing requests for testing DNS connectivity.java.text.ParseException
- if domain is not a valid domain name.DnssecException
- when a DNSSEC validation failure occurred.public static java.lang.String[][] getNAPTRRecords(java.lang.String domain) throws java.text.ParseException, DnssecException
domain
- the name of the domain we'd like to resolve.java.text.ParseException
- if domain is not a valid domain name.DnssecException
- when a DNSSEC validation failure occurred.public static java.net.InetAddress getInetAddress(java.lang.String hostAddress) throws java.net.UnknownHostException
hostAddress
- the String representation of the address
that we would like to create an InetAddress instance for.java.net.UnknownHostException
- if any of the InetAddress methods
we are using throw an exception.public static java.net.InetSocketAddress[] getAandAAAARecords(java.lang.String domain, int port) throws java.text.ParseException, DnssecException
domain
- the name of the domain we'd like to resolve.port
- the port number of the returned InetSocketAddressjava.text.ParseException
- if domain is not a valid domain name.DnssecException
- when a DNSSEC validation failure occurred.public static java.net.InetSocketAddress getARecord(java.lang.String domain, int port) throws java.text.ParseException, DnssecException
domain
- the name of the domain we'd like to resolve.port
- the port number of the returned InetSocketAddressjava.text.ParseException
- if domain is not a valid domain name.DnssecException
- when a DNSSEC validation failure occurred.public static java.net.InetSocketAddress getAAAARecord(java.lang.String domain, int port) throws java.text.ParseException, DnssecException
domain
- the name of the domain we'd like to resolve.port
- the port number of the returned InetSocketAddressjava.text.ParseException
- if domain is not a valid domain name.DnssecException
public static boolean isValidPortNumber(int port)
port
- the port number that we'd like verified.public static byte[] mappedIPv4ToRealIPv4(byte[] addr)
addr
- a String representing an IPv4-Mapped address in textual
formatpublic static int compareDnsNames(java.lang.String dns1, java.lang.String dns2) throws java.text.ParseException
dns1
- The first DNS namedns2
- The DNS name that is compared against dns1java.text.ParseException
- if the dns1 or dns2 is not a DNS Namepublic static void clearDefaultDNSCache()
Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under Apache license.