python-nmap的使用
2021-02-17 15:20
标签:style pexpect root pass class argument ls -l scanner scan python中的ssh登录模块 python-nmap的使用 标签:style pexpect root pass class argument ls -l scanner scan 原文地址:https://www.cnblogs.com/majianyu/p/12696148.htmlimport nmap
nm = nmap.PortScanner()
nm.scan(hosts="192.168.1.1/24", arguments="-n -sP -PE")
nm.all_hosts()
import telnetlib
tm = telnetlib.Telnet(host="192.168.1.30", port=‘22‘, timeout=4)
tm.read_until("\n", timeout=5)
import pexpect
pexpect.run("ls /tmp", withexitstatus=1)
chk = pexpect.spawn("ls -l /tmp/")
chk = pexpect.spawn("ls", [‘-l‘, ‘/tmp/‘])
ssh_k = pexpect.spawn(‘ssh root@192.168.1.245 -p22‘)
ssh_k.expect("password:")
ssh_k.expect("[p,P]assword:")
#匹配多种结果
ssh_k.expect([pexpect.TIMEOUT, pexpect.EOF, "password"])