Class NbtAddress
- java.lang.Object
-
- jcifs.netbios.NbtAddress
-
- All Implemented Interfaces:
Address
,NetbiosAddress
public final class NbtAddress extends Object implements NetbiosAddress
This class represents a NetBIOS over TCP/IP address. Under normal conditions, users of jCIFS need not be concerned with this class as name resolution and session services are handled internally by the smb package.Applications can use the methods
getLocalHost
,getByName
, andgetAllByAddress
to create a new NbtAddress instance. This class is symmetric withInetAddress
.About NetBIOS: The NetBIOS name service is a dynamic distributed service that allows hosts to resolve names by broadcasting a query, directing queries to a server such as Samba or WINS. NetBIOS is currently the primary networking layer for providing name service, datagram service, and session service to the Microsoft Windows platform. A NetBIOS name can be 15 characters long and hosts usually registers several names on the network. From a Windows command prompt you can see what names a host registers with the nbtstat command.
C:\>nbtstat -a 192.168.1.15 NetBIOS Remote Machine Name Table Name Type Status --------------------------------------------- JMORRIS2 <00> UNIQUE Registered BILLING-NY <00> GROUP Registered JMORRIS2 <03> UNIQUE Registered JMORRIS2 <20> UNIQUE Registered BILLING-NY <1E> GROUP Registered JMORRIS <03> UNIQUE Registered MAC Address = 00-B0-34-21-FA-3B
The hostname of this machine is
JMORRIS2
. It is a member of the group(a.k.a workgroup and domain)BILLING-NY
. To obtain anInetAddress
for a host one might do:InetAddress addr = NbtAddress.getByName("jmorris2").getInetAddress();
From a UNIX platform with Samba installed you can perform similar diagnostics using the
nmblookup
utility.- Since:
- jcifs-0.1
- Author:
- Michael B. Allen
- See Also:
InetAddress
-
-
Field Summary
Fields Modifier and Type Field Description static String
ANY_HOSTS_NAME
This is a special name that means all hosts.static int
B_NODE
A B node only broadcasts name queries.static int
H_NODE
A Hybrid node tries to resolve a name using the nameserver first.static int
M_NODE
Try Broadcast queries first, then try to resolve the name using the nameserver.static String
MASTER_BROWSER_NAME
This is a special name for querying the master browser that serves the list of hosts found in "Network Neighborhood".static int
P_NODE
A Point-to-Point node, or P node, unicasts queries to a nameserver only.static String
SMBSERVER_NAME
A special generic name specified when connecting to a host for which a name is not known.static byte[]
UNKNOWN_MAC_ADDRESS
Unknown MAC Address
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Determines if this address is equal two another.String
firstCalledName()
Guess next called name to try for session establishment.byte[]
getAddress()
Returns the raw IP address of this NbtAddress.String
getHostAddress()
Returns this IP adress as aString
in the form "%d.%d.%d.%d".String
getHostName()
The hostname of this address.InetAddress
getInetAddress()
To convert this address to anInetAddress
.byte[]
getMacAddress(CIFSContext tc)
Retrieves the MAC address of the remote network interface.NetbiosName
getName()
int
getNameType()
Returned the hex code associated with this name(e.g.int
getNodeType(CIFSContext tc)
Checks the node type of this address.int
hashCode()
Returns a hashcode for this IP address.boolean
isActive(CIFSContext tc)
Determines if this address is active.boolean
isBeingDeleted(CIFSContext tc)
Determines if this address in the process of being deleted.boolean
isGroupAddress(CIFSContext tc)
Determines if the address is a group address.boolean
isInConflict(CIFSContext tc)
Determines if this address in conflict with another address.boolean
isPermanent(CIFSContext tc)
Determines if this address is set to be permanent.String
nextCalledName(CIFSContext tc)
Guess next called name to try for session establishment.InetAddress
toInetAddress()
String
toString()
Returns theString
representaion of this address.<T extends Address>
Tunwrap(Class<T> type)
-
-
-
Field Detail
-
ANY_HOSTS_NAME
public static final String ANY_HOSTS_NAME
This is a special name that means all hosts. If you wish to find all hosts on a network querying a workgroup group name is the preferred method.- See Also:
- Constant Field Values
-
MASTER_BROWSER_NAME
public static final String MASTER_BROWSER_NAME
This is a special name for querying the master browser that serves the list of hosts found in "Network Neighborhood".- See Also:
- Constant Field Values
-
SMBSERVER_NAME
public static final String SMBSERVER_NAME
A special generic name specified when connecting to a host for which a name is not known. Not all servers respond to this name.- See Also:
- Constant Field Values
-
B_NODE
public static final int B_NODE
A B node only broadcasts name queries. This is the default if a nameserver such as WINS or Samba is not specified.- See Also:
- Constant Field Values
-
P_NODE
public static final int P_NODE
A Point-to-Point node, or P node, unicasts queries to a nameserver only. Natrually thejcifs.netbios.nameserver
property must be set.- See Also:
- Constant Field Values
-
M_NODE
public static final int M_NODE
Try Broadcast queries first, then try to resolve the name using the nameserver.- See Also:
- Constant Field Values
-
H_NODE
public static final int H_NODE
A Hybrid node tries to resolve a name using the nameserver first. If that fails use the broadcast address. This is the default if a nameserver is provided. This is the behavior of Microsoft Windows machines.- See Also:
- Constant Field Values
-
UNKNOWN_MAC_ADDRESS
public static final byte[] UNKNOWN_MAC_ADDRESS
Unknown MAC Address
-
-
Method Detail
-
unwrap
public <T extends Address> T unwrap(Class<T> type)
- Specified by:
unwrap
in interfaceAddress
- Returns:
- instance for type, null if the type cannot be unwrapped
- See Also:
Address.unwrap(java.lang.Class)
-
firstCalledName
public String firstCalledName()
Guess next called name to try for session establishment. These methods are used by the smb package.- Specified by:
firstCalledName
in interfaceAddress
- Returns:
- guessed name
-
nextCalledName
public String nextCalledName(CIFSContext tc)
Description copied from interface:Address
Guess next called name to try for session establishment. These methods are used by the smb package.- Specified by:
nextCalledName
in interfaceAddress
- Parameters:
tc
- context to use- Returns:
- net name to try
-
isGroupAddress
public boolean isGroupAddress(CIFSContext tc) throws UnknownHostException
Description copied from interface:NetbiosAddress
Determines if the address is a group address. This is also known as a workgroup name or group name.- Specified by:
isGroupAddress
in interfaceNetbiosAddress
- Parameters:
tc
- context to use- Returns:
- whether the given address is a group address
- Throws:
UnknownHostException
- if the host cannot be resolved to find out.
-
getNodeType
public int getNodeType(CIFSContext tc) throws UnknownHostException
Description copied from interface:NetbiosAddress
Checks the node type of this address.- Specified by:
getNodeType
in interfaceNetbiosAddress
- Parameters:
tc
- context to use- Returns:
B_NODE
,P_NODE
,M_NODE
,H_NODE
- Throws:
UnknownHostException
- if the host cannot be resolved to find out.
-
isBeingDeleted
public boolean isBeingDeleted(CIFSContext tc) throws UnknownHostException
Description copied from interface:NetbiosAddress
Determines if this address in the process of being deleted.- Specified by:
isBeingDeleted
in interfaceNetbiosAddress
- Parameters:
tc
- context to use- Returns:
- whether this address is in the process of being deleted
- Throws:
UnknownHostException
- if the host cannot be resolved to find out.
-
isInConflict
public boolean isInConflict(CIFSContext tc) throws UnknownHostException
Description copied from interface:NetbiosAddress
Determines if this address in conflict with another address.- Specified by:
isInConflict
in interfaceNetbiosAddress
- Parameters:
tc
- context to use- Returns:
- whether this address is in conflict with another address
- Throws:
UnknownHostException
- if the host cannot be resolved to find out.
-
isActive
public boolean isActive(CIFSContext tc) throws UnknownHostException
Description copied from interface:NetbiosAddress
Determines if this address is active.- Specified by:
isActive
in interfaceNetbiosAddress
- Parameters:
tc
- context to use- Returns:
- whether this address is active
- Throws:
UnknownHostException
- if the host cannot be resolved to find out.
-
isPermanent
public boolean isPermanent(CIFSContext tc) throws UnknownHostException
Description copied from interface:NetbiosAddress
Determines if this address is set to be permanent.- Specified by:
isPermanent
in interfaceNetbiosAddress
- Parameters:
tc
- context to use- Returns:
- whether this address is permanent
- Throws:
UnknownHostException
- if the host cannot be resolved to find out.
-
getMacAddress
public byte[] getMacAddress(CIFSContext tc) throws UnknownHostException
Description copied from interface:NetbiosAddress
Retrieves the MAC address of the remote network interface. Samba returns all zeros.- Specified by:
getMacAddress
in interfaceNetbiosAddress
- Parameters:
tc
- context to use- Returns:
- the MAC address as an array of six bytes
- Throws:
UnknownHostException
- if the host cannot be resolved to determine the MAC address.
-
getHostName
public String getHostName()
The hostname of this address. If the hostname is null the local machines IP address is returned.- Specified by:
getHostName
in interfaceAddress
- Returns:
- the text representation of the hostname associated with this address
-
getName
public NetbiosName getName()
- Specified by:
getName
in interfaceNetbiosAddress
- Returns:
- the name for this address
-
getAddress
public byte[] getAddress()
Returns the raw IP address of this NbtAddress. The result is in network byte order: the highest order byte of the address is in getAddress()[0].- Returns:
- a four byte array
-
getInetAddress
public InetAddress getInetAddress() throws UnknownHostException
To convert this address to anInetAddress
.- Returns:
- the
InetAddress
representation of this address. - Throws:
UnknownHostException
-
toInetAddress
public InetAddress toInetAddress() throws UnknownHostException
- Specified by:
toInetAddress
in interfaceAddress
- Returns:
- this address as an InetAddress
- Throws:
UnknownHostException
-
getHostAddress
public String getHostAddress()
Returns this IP adress as aString
in the form "%d.%d.%d.%d".- Specified by:
getHostAddress
in interfaceAddress
- Returns:
- string representation of the IP address
-
getNameType
public int getNameType()
Description copied from interface:NetbiosAddress
Returned the hex code associated with this name(e.g. 0x20 is for the file service)- Specified by:
getNameType
in interfaceNetbiosAddress
- Returns:
- the name type
-
hashCode
public int hashCode()
Returns a hashcode for this IP address. The hashcode comes from the IP address and is not generated from the string representation. So because NetBIOS nodes can have many names, all names associated with an IP will have the same hashcode.
-
equals
public boolean equals(Object obj)
Determines if this address is equal two another. Only the IP Addresses are compared. Similar to thehashCode()
method, the comparison is based on the integer IP address and not the string representation.
-
-