Q:

How can I determine the IP of my router/gateway in Java?

0

How can I determine the IP of my router/gateway in Java?

I can get my internet IP using a service on a website. But how can I determine my gateway's IP?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.io.*;
import java.util.*;
public class ExecTest {
    public static void main(String[] args) throws IOException {
        Process result = Runtime.getRuntime().exec("traceroute -m 1 www.amazon.com");
        BufferedReader output = new BufferedReader(new InputStreamReader(result.getInputStream()));
        String thisLine = output.readLine();
        StringTokenizer st = new StringTokenizer(thisLine);
        st.nextToken();
        String gateway = st.nextToken();
        System.out.printf("The gateway is %s\n", gateway);
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now