public class NetUtilities
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ARG_TEST_HOSTS
"-testhosts" followed by a series of hostname separated by semi-colon, such as "-testhosts host1;host2;host3;host4"
|
static java.lang.String |
LOCAL_HOST
'localhost'
|
static java.lang.String |
LOCAL_HOST_IP
'127.0.0.1'
|
static java.lang.String |
LOCAL_HOST_IPV6_PREFIX_1
'::1'
|
static java.lang.String |
LOCAL_HOST_IPV6_PREFIX_FE80
'fe80::'
|
static java.lang.String |
PATTERN_MAC_ADDRESS
"^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$" the regex pattern for a MAC address.
|
Constructor and Description |
---|
NetUtilities() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getHostIP(java.lang.String hostname)
Get the host's IP address.
|
static java.lang.String |
getLocalHostIP()
Get the localhost's IP Address.
|
static java.lang.String |
getLocalHostName() |
static boolean |
isHttpURLReachable(java.net.URL url,
int timeout)
Detect if url is reachable withing timeout.
|
static boolean |
isLocalHost(java.lang.String host)
Test if the host is local according to the host's name.
|
static boolean |
isMacAddress(java.lang.String address) |
static void |
main(java.lang.String[] args)
Test some implementations of this class.
To test isLocalHost(String) and getHostIP(String) , call as following:org.safs.net.NetUtilities -testhosts host1;host2;host3;host4 |
static java.lang.String |
readHttpURL(java.net.URL url,
java.lang.String encoding,
int timeout)
Read from url connection.
If the HTTP response code is 200, then the content is read from standard out stream. Otherwise, the content is read from the standard error stream. |
public static final java.lang.String LOCAL_HOST
public static final java.lang.String LOCAL_HOST_IP
public static final java.lang.String LOCAL_HOST_IPV6_PREFIX_1
public static final java.lang.String LOCAL_HOST_IPV6_PREFIX_FE80
public static final java.lang.String PATTERN_MAC_ADDRESS
public static final java.lang.String ARG_TEST_HOSTS
public static boolean isLocalHost(java.lang.String host)
host
- String, the name/ip of the hostpublic static boolean isMacAddress(java.lang.String address)
address
- String, the address to be testedpublic static java.lang.String getHostIP(java.lang.String hostname)
hostname
- String, the name of a hostpublic static java.lang.String getLocalHostIP()
NativeWrapper.COMMAND_IPCONFIG
.public static java.lang.String getLocalHostName()
public static java.lang.String readHttpURL(java.net.URL url, java.lang.String encoding, int timeout)
url
- URL, the url from where to read contentencoding
- String, the encoding used to read the URL, such as "utf-8"timeout
- int, the connect timeout in millisecondspublic static boolean isHttpURLReachable(java.net.URL url, int timeout)
url
- URL, the url from where to read contenttimeout
- int, the connect timeout in millisecondspublic static void main(java.lang.String[] args)
isLocalHost(String)
and getHostIP(String)
, call as following:org.safs.net.NetUtilities -testhosts host1;host2;host3;host4
args
- String[], isLocalHost(String)
and getHostIP(String)
IndependantLog.ARG_DEBUG
followed by host name such as machine.domain.com, then #test_getHostIp(String[])
Copyright © SAS Institute. All Rights Reserved.