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

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

Add Comment
1 Answer(s)

In java it is not as easy and straight forward like other languages

public class IPTest{
public static void main(String[] args) throws IOException {
Process result = Runtime.getRuntime().exec(“traceroute -m 1 www.coclouder.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);
}
}

Answered on July 24, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.