如题!!网上找了一些,但没理想的
前来csdn赐教
问问大家
java怎么获得多网卡的 本地ip假如我有一个 form1 form2 form3 几个网卡 几个form 
然后把ip写进from里!!
进行修改 ip 地址 高手赐教!!小弟感谢万分!!![color=#FF0000]
[/color]

解决方案 »

  1.   

    InetAddress.getLocalHost().getHostAddress()
    能得到单网卡
    我机子上就一个网卡等高手
      

  2.   

    InetAddress.getLocalHost().getHostAddress() 
      

  3.   


    try {
            InetAddress addr = InetAddress.getLocalHost();
        
            // Get IP Address
            byte[] ipAddr = addr.getAddress();
        
            // Get hostname
            String hostname = addr.getHostName();
        } catch (UnknownHostException e) {
        }
    这是获得单网卡的例子
      

  4.   


    public String getLocalHostName() {
    String hostName;
    try {
    InetAddress addr = InetAddress.getLocalHost();
    hostName = addr.getHostName();
    } catch (Exception ex) {
    hostName = "";
    }
    return hostName;
    }public String[] getAllLocalHostIP() {
    String[] ret = null;
    try {
    String hostName = getLocalHostName();
    if (hostName.length() > 0) {
    InetAddress[] addrs = InetAddress.getAllByName(hostName);
    if (addrs.length > 0) {
    ret = new String[addrs.length];
    for (int i = 0; i < addrs.length; i++) {
    ret[i] = addrs[i].getHostAddress();
    }
    }
    } } catch (Exception ex) {
    ret = null;
    }
    return ret;
    }
      

  5.   


    都是好强呀,我对于这个例子,运行了,能实现本地用户的查询呀!嗨,不错呀,看到j2se还是要学的呀!