如题

解决方案 »

  1.   

    public void showAllNetworkInterface() {
    NetworkInterface nif;
    try {
    Enumeration em = NetworkInterface.getByName("localhost")
    .getNetworkInterfaces();
    while (em.hasMoreElements()) {
    nif = (NetworkInterface) em.nextElement();

    System.out.print(nif.getDisplayName());
    Enumeration me = nif.getInetAddresses();
    while (me.hasMoreElements()) {
    System.out.print(" : " + me.nextElement());
    }
    System.out.println();
    }
    } catch (Exception e) {
    }
    }
      

  2.   

    InetAddress la=InetAddress.getLocalHost();
        String strHostName=la.getHostName();