java.lang.Object
com.voytechs.jnetstream.primitive.address.Address
com.voytechs.jnetstream.primitive.address.IpAddress
- public class IpAddress
- extends Address
A Class for storing IP Addresses
Currently is only designed to utilize IPv4 (32bit) addresses.
Class also contains utility methods for DNS lookups.
There are various functions for converting the IP address to a LONG.
Why would you want to use a long for storage of an IP address, in my
case I store IP address in a database as an UNSIGNED INT, java does not
have unsigned numbers so you have to go to next bigger primitive type to store
it or do like other implementations do store the address in a byte array.
|
Constructor Summary |
IpAddress(byte[] address)
Main constructor taking the array of bytes as the address. |
IpAddress(java.lang.String hostname)
Constructor taking a hostname. |
| Methods inherited from class com.voytechs.jnetstream.primitive.address.Address |
AND, AND, byteArrayValue, compare, compare, compareTo, EOR, EOR, equals, getByte, getByte, getRadix, INVERT, INVERT, longToByteArray, OR, OR, parseByteArray, setAddress, setByteArrayAddress, setFormat, setFormat, setRadix, setSeparator, stringValue, toByteArray, toString, toString |
inetAddress
private java.net.InetAddress inetAddress
hostname
private java.lang.String hostname
domainname
private java.lang.String domainname
IpAddress
public IpAddress(byte[] address)
- Main constructor taking the array of bytes as the address.
Automatically sets the separator token between '.' and ':' depending
on number of bytes in the address. 4 bytes IPv4 address with '.' separator
and 32 bytes for IPv6 address with ':' as separator.
IpAddress
public IpAddress(java.lang.String hostname)
throws java.net.UnknownHostException
- Constructor taking a hostname.
This is a conveniece constructor which converts the hostname to
numerical format internally. Currently only IPv4 addresses can be initialized this way
due to java.net library limitations.
getHostname
public java.lang.String getHostname()
- Do a DNS lookup on our IP address by use of DNS reverse lookup.
getDomainname
public java.lang.String getDomainname()
- Do a domain name lookup by use of DNS reverse lookup on the IP addresses
toString
public java.lang.String toString()
- Convert to dot notation string representation of the address. If hostname is
known then hostname.domain is returned other wise the appropriate numerical
representation of the numerical address is returned as a String.
- Overrides:
toString in class Address
main
public static void main(java.lang.String[] args)
- Test function for IpAddress