python-nmap的使用

import 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)

python中的ssh登录模块

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  -p22‘)
ssh_k.expect("password:")
ssh_k.expect("[p,P]assword:")
#匹配多种结果
ssh_k.expect([pexpect.TIMEOUT, pexpect.EOF, "password"])

相关推荐