только 2 команды: connect, disconnect. точно таким же образом можно добавить restart, предварительно посмотрев на какой HTTP-пакет модем согласится рестартиться. отключив GUI, можно прикрутить вызов этого безобразия к cron'у и дергать автоматом. успехов )
Код:
import javax.swing.*;
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.regex.*;
public class DLinkConnection
{
public static void main ( String args[] )
{
try{
final int BUFSZ = 1000;
byte buf[] = new byte[BUFSZ];
if ( args.length != 2 )
error( "Usage: login:pass@host:port connect|disconnect" );
String connect = "0";
if ( !args[1].equals("connect") &&
!args[1].equals("disconnect") )
error( "connect|disconnect" );
else if ( args[1].equals("connect") )
connect = "1";
String conf[] = args[0].split("@");
if ( conf.length != 2 )
error( "auth@conn" );
String auth[] = conf[0].split(":");
if ( auth.length != 2 )
error( "login:path" );
String conn[] = conf[1].split(":");
if ( conn.length != 2 )
error( "host:ip" );
int port = Integer.parseInt(conn[1]);
String host = conn[0];
String len = new Integer( 139 + auth[0].length() + auth[1].length() ).toString();
String authPost[] = {
"POST /cgi-bin/webcm HTTP/1.1",
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*",
"Referer: http://" + host,
"Accept-Language: ru",
"Content-Type: application/x-www-form-urlencoded",
"Accept-Encoding: gzip, deflate",
"User-Agent: Own",
"Host: "+ host,
"Content-Length: " + len,
"Connection: Keep-Alive",
"Cache-Control: no-cache",
"",
"getpage=..%2Fhtml%2Fframe.htm&errorpage=..%2Fhtml%2Findex.html&login%3Acommand%2Fusername=" + auth[0] + "&login%3Acommand%2Fpassword=" + auth[1] + "&var%3Aerrormsg=Error"
};
String adminPost[] = {
"POST /cgi-bin/webcm HTTP/1.1",
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*",
"Referer: http://" + host + "/cgi-bin/webcm",
"Accept-Language: ru",
"Content-Type: application/x-www-form-urlencoded",
"Accept-Encoding: gzip, deflate",
"User-Agent: Own",
"Host: " + host,
"Content-Length: 82",
"Connection: Keep-Alive",
"Cache-Control: no-cache",
"",
"getpage=..%2Fhtml%2Fstatus%2Fconnstatus.htm&connection0%3Asettings%2Fmanual_conn=" + connect
};
int n;
String delim = "\r\n";
final JProgressBar progressBar = new JProgressBar( 0, 100 );
progressBar.setIndeterminate(true);
JDialog frame = new JDialog( new Frame(), args[1].equals("disconnect") ?
"Disconnecting!" : "Connecting!" );
JPanel panel = new JPanel();
panel.add(progressBar);
frame.getContentPane().add(panel);
frame.pack();
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
frame.setLocation( screenSize.width/2 - frameSize.width/2,
screenSize.height/2 - frameSize.height/2 );
frame.requestFocus();
frame.setVisible(true);
Socket client = new Socket( host, port );
OutputStream out = client.getOutputStream();
InputStream in = client.getInputStream();
for ( int i=0; i < authPost.length; ++i )
{
out.write( authPost[i].getBytes(), 0, authPost[i].length() );
out.write( delim.getBytes(), 0, delim.length() );
out.flush();
}
StringBuffer strBuf = new StringBuffer();
while ( ( n = in.read(buf) ) > 0 )
strBuf.append( new String(buf, 0, n).toCharArray(), 0, n );
client.close();
if ( -1 != strBuf.toString().indexOf( "Your Login Name / Password is Invalid" ) )
error( "Authentication error!" );
client = new Socket( host, port );
out = client.getOutputStream();
in = client.getInputStream();
for ( int i=0; i < adminPost.length; ++i )
{
out.write( adminPost[i].getBytes(), 0, adminPost[i].length() );
out.write( delim.getBytes(), 0, delim.length() );
out.flush();
}
strBuf = new StringBuffer();
while ( ( n = in.read(buf) ) > 0 )
strBuf.append( new String(buf, 0, n).toCharArray(), 0, n );
client.close();
if ( args[1].equals("disconnect") )
ok( "Successfully disconnected!" );
else
{
ok( "Successfully connected!" );
/*
System.out.println( strBuf.toString() );
Pattern p = Pattern.compile( "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}" );
Matcher m = p.matcher( strBuf.toString() );
if ( m.matches() )
ok( m.group() );
*/
}
System.exit(0);
}
catch ( Exception e )
{
error( e.toString() );
}
}
public static void error ( String str )
{
JOptionPane.showMessageDialog( new Frame(),
str,
"Try again",
JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
public static void ok ( String str )
{
JOptionPane.showMessageDialog( new Frame(),
str,
"Success!",
JOptionPane.INFORMATION_MESSAGE);
}
};