Strumenti Utente

Strumenti Sito


lpr-b:nslookup
no way to compare when less than two revisions

Differenze

Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.


lpr-b:nslookup [13/11/2007 alle 18:54 (18 anni fa)] (versione attuale) – creata Marco Danelutto
Linea 1: Linea 1:
 +<code java>
 +package nslookup;
  
 +import java.io.IOException;
 +import java.io.ObjectInputStream;
 +import java.io.ObjectOutputStream;
 +import java.net.InetAddress;
 +import java.net.Socket;
 +import java.net.UnknownHostException;
 +
 +public class Nslookup {
 +
 +        /**
 +         * @param args
 +         */
 +        public static void main(String[] args) {
 +
 +                if(args.length == 0) {
 +                        System.out.println("Usage is:\njava Nslookup nameserver hostname [true!false]");
 +                        return;
 +                }
 +                String serverName = args[0];
 +                String hostName = args[1];
 +                boolean cached = Boolean.parseBoolean(args[2]);
 +                
 +                InetAddress sa = null;
 +                try {
 +                        System.out.println("Ricerca indirizzo per NameServer su "+serverName);
 +                        sa = InetAddress.getByName(serverName);
 +                        System.out.println("NameServer:"+sa);
 +                } catch (UnknownHostException e) {
 +                        System.out.println("Host "+serverName+" sconosciuto");
 +                        return;
 +                }
 +                Socket s = null; 
 +                try {
 +                        s = new Socket(sa,NameServer.NAMESERVERPORT);
 +                } catch (IOException e) {
 +                        System.out.println("Errore nella connessione con il NameServer");
 +                        return;
 +                }
 +                ObjectOutputStream oos;
 +                try {
 +                        oos = new ObjectOutputStream(s.getOutputStream());
 +                } catch (IOException e) {
 +                        System.out.println("Errore nella creazione dell'ObjectOutputStream");
 +                        return;
 +                }
 +                NameQuery nq = new NameQuery(hostName,cached);
 +                long t0 = System.currentTimeMillis();
 +                try {
 +                        oos.writeObject(nq);
 +                } catch (IOException e) {
 +                        System.out.println("Errore nell'invio della richiesta");
 +                        return;
 +                }
 +                ObjectInputStream ois = null;
 +                try {
 +                        ois = new ObjectInputStream(s.getInputStream());
 +                } catch (IOException e) {
 +                        System.out.println("Errore nella creazione dell?ObjectInputStream");
 +                }
 +                QueryAnswer qa = null;
 +                long t1 = 0L;
 +                try {
 +                        qa = (QueryAnswer) ois.readObject();
 +                        t1 = System.currentTimeMillis();
 +                } catch (IOException e) {
 +                        System.out.println("Errore nella lettura della risposta");
 +                        return;
 +                } catch (ClassNotFoundException e) {
 +                        System.out.println("Errore: tipo sconosciuto dell'oggetto letto");
 +                        return;
 +                }
 +                System.out.println("NsLookup "+hostName+":"+qa.getInetAddress());
 +                System.out.println("Impiegati "+(t1-t0)+" msec");
 +        }
 +
 +}
 +</code>
lpr-b/nslookup.txt · Ultima modifica: 13/11/2007 alle 18:54 (18 anni fa) da Marco Danelutto

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki