Skip to content

Instantly share code, notes, and snippets.

@demircancelebi
Created July 9, 2015 00:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demircancelebi/4d86765af03bd6ed03f0 to your computer and use it in GitHub Desktop.
Save demircancelebi/4d86765af03bd6ed03f0 to your computer and use it in GitHub Desktop.
node.js modem reset
/*
Usage:
You should allow telnet in modem settings beforehand (might be allowed already)
You should set opts according to your modem settings
loginText = When you try `telnet 192.168.2.1` in terminal
it asks you login name for the modem. Change
this text to something you see on that line.
I saw my modem name and used that.
routerDefaultIP = might be different for different modems,
192.168.1.1 is also common AFAIK
username = username for access to modem interface,
'root' or 'admin' is common
password = password for access to modem interface
commandDelimiter = you probably do not have to change this,
either '#' or '>' should work
*/
var opts = {
loginText: 'Air5750',
routerDefaultIP: '192.168.2.1',
username: 'root',
password: 'thisisyourpass',
commandDelimiter: '#'
};
var spawn = require('child_process').spawn,
child = spawn('telnet', [opts.routerDefaultIP]);
child.stdout.on('data', function (data) {
if(data.toString('utf8').indexOf(opts.loginText)>-1) {
child.stdin.write(opts.username + '\n');
} else if(data.toString('utf8').indexOf('Password')>-1) {
child.stdin.write(opts.password + '\n');
} else if(data.toString('utf8').indexOf(opts.commandDelimiter)>-1) {
child.stdin.write('reboot\n');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment