Skip to content

Instantly share code, notes, and snippets.

@Hexagon
Created January 27, 2016 11:59
Show Gist options
  • Save Hexagon/8d3d02f2b0f4b94d8d9e to your computer and use it in GitHub Desktop.
Save Hexagon/8d3d02f2b0f4b94d8d9e to your computer and use it in GitHub Desktop.
var telnet = require('telnet-client');
var connection = new telnet();
var params = {
host: 'horizons.jpl.nasa.gov',
port: 6775,
shellPrompt: 'Horizons> ',
timeout: 5000
};
var commands = [
["399"," Select ... [E]phemeris, [F]tp, [M]ail, [R]edisplay, ?, <cr>: ", true],
["e", " Observe, Elements, Vectors [o,e,v,?] :", false],
["v", " Coordinate center [ <id>,coord,geo ] :", false],
["@sun", " Reference plane [eclip, frame, body ] :", false],
["eclip", " Starting CT [>= 9999BC-Mar-20 00:00] :", false],
["2016-01-24 00:00:00", " Ending CT [<= 9999-Dec-31 12:00] :", false],
["2016-01-24 01:00:00", " Output interval [ex: 10m, 1h, 1d, ? ] :", false],
["1d", " Accept default output [ cr=(y), n, ?] :", false],
["y", " >>> Select... [A]gain, [N]ew-case, [F]tp, [K]ermit, [M]ail, [R]edisplay, ? :", true]
];
connection.on('ready', function(prompt) {
console.log('Connected');
(function recursiveCommands(i, result) {
i = (i !== undefined) ? i : 0;
result = result || [];
console.log('Executing: ' , commands[i][0], ' awaiting ', commands[i][1]);
connection.exec(commands[i][0], {shellPrompt: commands[i][1]}, function(err, response) {
//console.log('Repsonse: ', err,response);
if(commands[i][2]) {
result.push(response);
}
if(i<commands.length-1) {
recursiveCommands(++i,result);
} else {
console.log(result[1]);
}
});
})();
});
connection.on('timeout', function() {
console.log('socket timeout!')
connection.end();
});
connection.on('close', function() {
console.log('connection closed');
});
connection.connect(params);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment