T
TCMA
How to write a java program to access a router which has management
address http://192.168.2.1?
I have a problem with the first step which is to login with password.
This is my java program.
import java.io.*;
import java.net.*;
public class router {
public static void main(String[] args) throws Exception {
try {
if (args.length != 1) {
System.err.println("Usage: java router password");
System.exit(1);
}
String password = URLEncoder.encode(args[0], "US-ASCII");
URL url = new URL("http://192.168.2.1/");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(
connection.getOutputStream());
out.println(password);
// out.println(args[0]);
out.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
}
This is the output which display the login screen,
it seems that my login fails, does not get past the login screen?
$ java router mypassword
<!---CAS:0003--><HTML><HEAD>
<TITLE>SMC7004VBR - LOGIN</TITLE></HEAD>
<FRAMESET ROWS="0,*" BORDER=0 FRAMEBORDER=NO FRAMESPACING=0>
<FRAME SRC="/menu0.htm" NAME="space" SCROLLING="NO" BORDER=0>
<!--FRAME SRC="/login.htm" NAME="bottom" scrolling="no" BORDER=0-->
<FRAME SRC="/login.htm" NAME="bottom" SCROLLING="NO" BORDER=0>
</FRAMESET></HTML>
address http://192.168.2.1?
I have a problem with the first step which is to login with password.
This is my java program.
import java.io.*;
import java.net.*;
public class router {
public static void main(String[] args) throws Exception {
try {
if (args.length != 1) {
System.err.println("Usage: java router password");
System.exit(1);
}
String password = URLEncoder.encode(args[0], "US-ASCII");
URL url = new URL("http://192.168.2.1/");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(
connection.getOutputStream());
out.println(password);
// out.println(args[0]);
out.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
}
This is the output which display the login screen,
it seems that my login fails, does not get past the login screen?
$ java router mypassword
<!---CAS:0003--><HTML><HEAD>
<TITLE>SMC7004VBR - LOGIN</TITLE></HEAD>
<FRAMESET ROWS="0,*" BORDER=0 FRAMEBORDER=NO FRAMESPACING=0>
<FRAME SRC="/menu0.htm" NAME="space" SCROLLING="NO" BORDER=0>
<!--FRAME SRC="/login.htm" NAME="bottom" scrolling="no" BORDER=0-->
<FRAME SRC="/login.htm" NAME="bottom" SCROLLING="NO" BORDER=0>
</FRAMESET></HTML>