日期:2014-05-20  浏览次数:21029 次

java如何获得本机的网关IP地址
如题

------解决方案--------------------
For Example:

Java code

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class ListAllFiles {

    public static void main(String[] args) {
        try {
            Process pro = Runtime.getRuntime()
                    .exec("cmd /c ipconfig /all");
            InputStreamReader isr = new InputStreamReader(pro.getInputStream());
            BufferedReader br = new BufferedReader(isr);
            String str = br.readLine();
            while(str!=null){
                System.out.println(str.trim());
                str = br.readLine();
            }
            br.close();
            isr.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}