[jcifs] Re: domain suffix

Eric Glass eric.glass at gmail.com
Fri Oct 20 09:26:31 GMT 2006


> If I can figure out the domain suffix, finding the IP is not a problem. I can
> just use "dig" in linux to lookup the IP.
>

I think I'm confused as to what you're looking for... it sounds like
you want to:

1) Locate a server/workstation via a WINS lookup (i.e. by the NetBIOS
host name).

2) Get the IP address corresponding to that machine.

3) Do a reverse DNS lookup to get the fully-qualified domain name for
the machine.

It sounds like you have #1 and #2 already, and can use dig etc. to do
#3 but are looking for a way to do it in Java, i.e. with jCIFS.

See if the below gives you what you are looking for; this does a
lookup of the name using jCIFS (i.e., depending on how you have your
jCIFS properties setup, could be a WINS lookup).  Then it converts it
to an InetAddress, which lets you do getCanonicalHostName; that should
do a reverse DNS lookup of the corresponding IP address and give you
the DNS FQDN.


import java.net.InetAddress;

import jcifs.UniAddress;

import jcifs.netbios.NbtAddress;

public class Lookup {

    public static void main(String[] args) throws Exception {
        String hostname = args[0];
        UniAddress uniAddress = UniAddress.getByName(hostname);
        Object address = uniAddress.getAddress();
        InetAddress inetAddress = (address instanceof InetAddress) ?
                (InetAddress) address : ((NbtAddress) address).getInetAddress();
        hostname = inetAddress.getCanonicalHostName();
        System.out.println(hostname);
    }

}


More information about the jcifs mailing list