iOS-NMSSH

2020-11-16  本文已影响0人  iLeooooo

在Swift项目中使用SSH登录路由器

使用三方库NMSSH连接

pod 'NMSSH'

xxx-Bridging-Header文件中导入头文件

// NMSSH
#import <NMSSH/NMSSH.h>

在项目中使用方法

let session = NMSSHSession.connect(toHost: "10.0.0.254", withUsername: "root")
if session.isConnected {
    print("Successfully created a new session")
}
session.authenticate(byPassword: "password")
if session.isAuthorized {
    print("Successfully authorized")
    let response = session.channel.execute("df -h", error: nil, timeout: 3)
    print("---res--\(response)")
}
session.disconnect()
上一篇下一篇

猜你喜欢

热点阅读