java program to access a router

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>
 
S

Sam

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>


I'd be interested in your results with this. I do know that there is a
network management protocol that works with the TCP/IP suite, SNMP. If
your router implments it, there's at least one Java package out there
that should work with it (from google):
http://www2.rad.com/networks/1995/snmp/snmp.htm.

Regards,
Sam90
 
T

TCMA

Which Java package out there that should work with it (from google)?

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>


I'd be interested in your results with this. I do know that there is a
network management protocol that works with the TCP/IP suite, SNMP. If
your router implments it, there's at least one Java package out there
that should work with it (from google):
http://www2.rad.com/networks/1995/snmp/snmp.htm.

Regards,
Sam90
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top