public class ServerAddress
extends java.lang.Object
Constructor and Description |
---|
ServerAddress(java.lang.String theIpAddress,
int thePort,
boolean asHttps)
Create a new instance of ServerAddress.
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkAddress(java.lang.String host,
int port)
Return true if the IP address and port compares to the address the server is running on.
|
static java.net.InetAddress |
getLocalHost4Address()
This code is third-party from the Internet.
|
java.lang.String |
getUrlAddress()
Return the URL address of the static HTTP server.
|
static java.util.ArrayList<java.lang.String> |
ips(java.lang.String hostAddress)
Retrieve a list of alternative ip addresses (127.0.0.1) for the local computer.
|
boolean |
isLocalIPAddress(java.lang.String theIPAddress)
Return true if the IP address represents a local server.
|
public ServerAddress(java.lang.String theIpAddress, int thePort, boolean asHttps) throws java.lang.Exception
theIpAddress
- the IP address to start the server on.thePort
- the port to run on.asHttps
- true if add as an https address and not an http address.java.lang.Exception
- any error.public boolean isLocalIPAddress(java.lang.String theIPAddress) throws java.lang.Exception
theIPAddress
- the IP address to compare. Note ip not url address.java.lang.Exception
- any error.public boolean checkAddress(java.lang.String host, int port) throws java.lang.Exception
host
- the host address. Can include 'localhost' or '127.0.0.1'.port
- the port.java.lang.Exception
- any error.public java.lang.String getUrlAddress()
public static java.net.InetAddress getLocalHost4Address() throws java.net.UnknownHostException
InetAddress
object encapsulating what is most
likely the machine's LAN IP address.
This has been changed to return an ipV4 address only. For any other type
you should include the address in startup script.
This method is intended for use as a replacement of JDK method
InetAddress.getLocalHost
, because that method is ambiguous
on Linux systems. Linux systems enumerate the loopback network interface
the same way as regular LAN network interfaces, but the JDK
InetAddress.getLocalHost
method does not specify the
algorithm used to select the address returned under such circumstances,
and will often return the loopback address, which is not valid for
network communication. Details
here.
This method will scan all IP addresses on all network interfaces on the host machine to determine the IP address most likely to be the machine's LAN address. If the machine has multiple IP addresses, this method will prefer a site-local IP address (e.g. 192.168.x.x or 10.10.x.x, usually IPv4) if the machine has one (and will return the first site-local address if the machine has more than one), but if the machine does not hold a site-local address, this method will return simply the first non-loopback address found (IPv4 or IPv6).
If this method cannot find a non-loopback address using this selection
algorithm, it will fall back to calling and returning the result of JDK
method InetAddress.getLocalHost
.
java.net.UnknownHostException
- If the LAN address of the machine cannot be
found.public static java.util.ArrayList<java.lang.String> ips(java.lang.String hostAddress) throws java.net.SocketException
hostAddress
- the current ip adress that the host is running on.
Can be null.java.net.SocketException
- network interface exception.