Ciao a tutti,
avrei bisogno di conoscere il nome del computer del visitatore che si collega al mio sito.
Pensavo di implementare un applet Java per questo scopo.
Qui sotto vi scrivo il codice che ho cercato di utilizzare.
Funziona perfettamente come programma stand-alone ma non
riesco a trasformarlo in applet.
Premetto che sono un programmatore Visual Basic e sto
iniziando adesso con Java..
Qualsiasi idea, anche completamente diversa è ben accetta
Grazie in anticipo
codice:/*L'idea è quella di caricare in un buffer il risultato del comando "ipconfig /all", ciclare il buffer e individuare la riga con il nome della macchina*/ import java.io.*; import java.util.*; public class GetHostName { public static void main(String[] args) throws IOException { System.out.println(getMachinesMAC()); } public static String getMachinesMAC() throws IOException { String sendback=null; Process proc = Runtime.getRuntime().exec("ipconfig /all"); InputStream istr = proc.getInputStream(); BufferedReader br =new BufferedReader(new InputStreamReader(istr)); String str; int tokens = 0; while ((str = br.readLine()) != null) { StringTokenizer st = new StringTokenizer(str); tokens = st.countTokens(); if(tokens > 1) {String temp = st.nextToken(); //lista = lista + '\n' + temp; if(temp.equals("Nome")) { /*for(int i=0; i<16;i++) temp=st.nextToken(); if (temp.equals(":")) { temp=st.nextToken(); sendback=temp; } }*/ while (temp.equals(":")==false) { temp=st.nextToken(); } temp=st.nextToken(); sendback=temp; } } } try {proc.waitFor();} catch (InterruptedException e) {System.err.println("process was interrupted");} br.close(); return sendback; } }