How to find the default gateway IP address in jsp

I want to know the default client gateway and DNS in jsp. Is there anyway to do this. I found out the IP address, but I also want to know the default gateway or DNS. I did the following to find the ip client.

String ipAddress = request.getHeader("X-FORWARDED-FOR");  
String getWay = request.getRemoteAddr() ;   // Gateway
out.println("<br/>IP Address:"+ipAddress+"<br/>");
out.println("<br/>Gateway:"+getWay+"<br/>");
+4
source share
2 answers

You can use this snippet and parse the answer:

p = Runtime.getRuntime().exec("ipconfig");
p.waitFor();

BufferedReader reader = 
     new BufferedReader(new InputStreamReader(p.getInputStream()));

String line = "";           
while ((line = reader.readLine())!= null) {
sb.append(line + "\n");
}
0
source

Follow the link below. Hope this answers your question: http://ireasoning.com/articles/find_local_ip_address.htm

The most reliable way is to use a route table. In the windows, the "print" route gives us something like:

Runtime.getRuntime(). exec (" cmd.exe/c route print ")

linux /proc/net/route

BufferedReader reader = new BufferedReader ( FileReader (" /Proc/ /"))

-1

Source: https://habr.com/ru/post/1613613/


All Articles