????λ?????????? >> ??????????
Python-Nmap??ü?????
??????????? ???????[ 2016/10/28 15:13:10 ] ????????Python-Nmap ???????
??????鰸??
??????????????????
????1.???庯????mytools.py
#-*- coding:utf-8 -*-
import smtplib
from email.mime.text import MIMEText
from email.header import Header
def sendemail(sender??receiver??subject??content??smtpserver??smtpuser??smtppass):
msg = MIMEText(content??'html'??'utf-8')#?????????‘utf-8'???????????????
msg['Subject'] = Header(subject?? 'utf-8')
msg['From'] = '<%s>' % sender
msg['To'] = ";".join(receiver)
try:
smtp = smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(smtpuser?? smtppass)
smtp.sendmail(sender?? receiver?? msg.as_string())
smtp.quit()
except Exception??e:
print e
????2. ?????????????????汾nmscan.py
# !/usr/bin/python
# -*- coding:utf-8 -*-
import nmap
import re
import mytools as tool
import sys
reload(sys)
sys.setdefaultencoding('utf8')
def nmScan(hostlist?? portrange?? whitelist):
p = re.compile("^(d*)-(d*)$")
if type(hostlist) != list:
help()
portmatch = re.match(p?? portrange)
if not portmatch:
help()
l = []
for host in hostlist:
result = ''
nm = nmap.PortScanner()
tmp = nm.scan(host?? portrange)
result = result + "<h2>ip???:%s ??????:[%s] ...... %s</h2><hr>" % (
host?? tmp['scan'][host]['hostname']?? tmp['scan'][host]['status']['state'])
try:
ports = tmp['scan'][host]['tcp'].keys()
except KeyError?? e:
if whitelist:
whitestr = '??'.join(whitelist)
result = result + "δ?????????!????%s????????????" % whitestr
else:
result = result + "??????????????????"
for port in ports:
info = ''
if port not in whitelist:
info = '<strong><font color=red>Alert:???????</font><strong> '
else:
info = '<strong><font color=green>Info:??????????</font><strong> '
portinfo = "%s <strong>port</strong> : %s <strong>state</strong> : %s <strong>product<strong/> : %s <br>" % (
info?? port?? tmp['scan'][host]['tcp'][port]['state']??
tmp['scan'][host]['tcp'][port]['product'])
result = result + portinfo
l.append([host?? str(result)])
return l
def help():
print "Usage: nmScan(['127.0.0.1'??]??'0-65535')"
if __name__ == "__main__":
hostlist = ['10.10.10.10'?? '10.10.10.11']
portrange = '0-65535'
whitelist = [80?? 443]
l = nmScan(hostlist?? portrange?? whitelist)
sender = '75501664@qq.com'
receiver = ['zhangyanlin8851@163.com'?? '877986976@qq.com']
subject = '????????????'
smtpserver = 'smtp.exmail.qq.com'
smtpuser = 'zhangyanlin8851@163.cn'
smtppass = 'linuxidc163'
mailcontent = ''
for i in range(len(l)):
mailcontent = mailcontent + l[i][1]
tool.sendemail(sender?? receiver?? subject?? mailcontent?? smtpserver?? smtpuser?? smtppass)
????3.?????汾
# !/usr/bin/python
# -*- coding:utf-8 -*-
import nmap
import re
import mytools as tool
import sys
from multiprocessing import Pool
from functools import partial
reload(sys)
sys.setdefaultencoding('utf8')
def nmScan(host?? portrange?? whitelist):
p = re.compile("^(d*)-(d*)$")
# if type(hostlist) != list:
# help()
portmatch = re.match(p?? portrange)
if not portmatch:
help()
if host == '121.42.32.172':
whitelist = [25?? ]
result = ''
nm = nmap.PortScanner()
tmp = nm.scan(host?? portrange)
result = result + "<h2>ip???:%s ??????:[%s] ...... %s</h2><hr>" % (
host?? tmp['scan'][host]['hostname']?? tmp['scan'][host]['status']['state'])
try:
ports = tmp['scan'][host]['tcp'].keys()
for port in ports:
info = ''
if port not in whitelist:
info = '<strong><font color=red>Alert:???????</font><strong> '
else:
info = '<strong><font color=green>Info:??????????</font><strong> '
portinfo = "%s <strong>port</strong> : %s <strong>state</strong> : %s <strong>product<strong/> : %s <br>" % (
info?? port?? tmp['scan'][host]['tcp'][port]['state']?? tmp['scan'][host]['tcp'][port]['product'])
result = result + portinfo
except KeyError?? e:
if whitelist:
whitestr = '??'.join(whitelist)
result = result + "δ?????????!????%s????????????" % whitestr
else:
result = result + "??????????????????"
return result
def help():
print "Usage: nmScan(['127.0.0.1'??]??'0-65535')"
return None
if __name__ == "__main__":
hostlist = ['10.10.10.10'?? '10.10.10.11']
portrange = '0-65535'
whitelist = [80?? 443]
l = nmScan(hostlist?? portrange?? whitelist)
sender = '75501664@qq.com'
receiver = ['zhangyanlin8851@163.com'?? '877986976@qq.com']
subject = '????????????'
smtpserver = 'smtp.exmail.qq.com'
smtpuser = 'zhangyanlin8851@163.cn'
smtppass = 'linuxidc163'
mailcontent = ''
for i in range(len(l)):
mailcontent = mailcontent + l[i][1]
tool.sendemail(sender?? receiver?? subject?? mailcontent?? smtpserver?? smtpuser?? smtppass)
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
???????????????????Щ???????????????????????????2017?????????????????????AutoRunner???????????????2016??1??8??V4.0?汾?????????????????????TestDirector?淶??????????WinRunner????????????????????WinRunner???????????????Winrunner TSL????????????????WinRunner?????????????????????????WinRunner?????????????????WinRunner???????????????????????????????????????????VectorCAST-?????????????????????????????????е??????????????????????????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????