I want to change the settings of a PROROUTE wireless cellular router (H685) from the web application.
The only way to change the settings, is to login to the router via telnet and change a file in the editor (i.e. vi) and reboot.

I want to do it programmatically from server side using JAVA,
I can connect to the router and send command, using TelnetClient

Here is the sample code to connect to the router via telnet and send command

```
public class Test
{
    private TelnetClient telnet = new TelnetClient();
    private InputStream in;
    private PrintStream out;
    private String prompt = "#";

    public Test(String server, String user, String password) {
        try {
            // Connect to the specified server
            telnet.connect(server, 23);
            // Get input and output stream references
            in = telnet.getInputStream();
            out = new PrintStream(telnet.getOutputStream());
            // Log the user on
            readUntil("Login:");
            write(user);
            readUntil("Password:");
            write(password);
            // Advance to a prompt
            readUntil(prompt + " ");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String readUntil(String pattern) {
        try {
            char lastChar = pattern.charAt(pattern.length() - 1);
            StringBuffer sb = new StringBuffer();
            boolean found = false;
            char ch = (char) in.read();
            while (true) {
                System.out.print(ch);
                sb.append(ch);
                if (ch == lastChar) {
                    if (sb.toString().endsWith(pattern)) {
                        return sb.toString();
                    }
                }
                ch = (char) in.read();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public void write(String value) {
        try {
            out.println(value);
            out.flush();
            System.out.println(value);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String sendCommand(String command) {
        try {
            write(command);
            return readUntil(prompt + " ");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public void disconnect() {
        try {
            telnet.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        try {
            Test telnet = new Test("192.168.1.1", "username", "pwd");
            telnet.sendCommand("ls");
            telnet.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

```

But I have to update the file in the editor.

1. Send command to open the file in vi

$vi /flash/.disable\_fun\_list

function\_dtu:

function\_wifi:

function\_gps:
.
.
.
.

function\_wifi:on (this line needs to be changed)

and then send command to restart the router.

$reboot

Any idea, how this can be done.