Ciao, se n'è già parlato comunque:
codice:
import java.net.*;
import java.util.*;
public class networkInterfaces {
Enumeration enNI;
public String toString() {
String temp = "";
if (enNI!=null) {
while (enNI.hasMoreElements()) {
temp += ((NetworkInterface)(enNI.nextElement())).toString() + "\n";
}
}
else {
temp += "Non è stato possibile recuperare le informazioni richieste";
}
return temp;
}
public networkInterfaces() {
try {
enNI = NetworkInterface.getNetworkInterfaces();
}
catch (Exception e) {
enNI = null;
}
}
public static void main (String[] args) {
networkInterfaces nn = new internetInterfaces();
System.out.print(nn.toString());
}
}
E' un esempio di come recuperare tutte le informazioni riguardanti ogni NetworkInterface attaccata alla macchina. Nel mio caso, non essendo dietro ad un proxy (o router), riesco a recuperare anche l'indirizzo IP della macchina in internet
codice:
name:lo (MS TCP Loopback interface) index: 1 addresses:
/127.0.0.1;
name:eth0 (NIC Fast Ethernet PCI Realtek RTL8139 Family - Miniport dell'Utilità di pianificazione pacchetti) index: 65539 addresses:
name:ppp0 (WAN (PPP/SLIP) Interface) index: 131076 addresses:
/87.2.241.xxx;
Non è detto che sia il tuo caso (anzi). Se ti interessa vedere con che indirizzo ip la tua macchina sia vista in internet, dovrai parsare i dati forniti da un qualche servizio esterno, del tipo:
http://www.whatismyipaddress.com/ o altri analoghi.