Python port scan

Source: Internet
Author: User

Some time ago wrote a port scan of the Python script, found that now forget almost, and quickly recorded it, although it is concurrent, but in the actual use of the scene, if the scan of too many machines, there is still a performance problem, fortunately I need to scan the machine on a few. The script writes the raw ...

The following attached source:

#!/usr/bin/env python#-*- coding:utf-8 -*-import nmapimport threadingimport  Smtplibimport stringfrom email.mime.text import mimetextfrom email.header import  headerimport sys# Prevent Chinese problems reload (SYS) sys.setdefaultencoding (' Utf-8 ') in Linux #设置白名单接口PortList =[22,80,xxx , XXX] #设置收件人列表: Multiple needs to be separated by commas, such as: [' [' [email protected] ', ' [email protected] ', ' [email protected] ']maillist =[' [email protected] ', ' [email protected] ', ' [email protected] '] #定义个全局变量以接受scan1函数中的变量result  =  ' #总共执行的主机数, from the ip.txt to read the host, of course, some of the requirements may be from the database, where you can modify Num=file (' Ip.txt ', ' R ') Hostnum=len (Num.readlines ( )) Num.close () #定义发邮件函数def  sendmail (sender,receiver,subject,content,smtpserver,smtpuser,smtppass):   msg = mimetext (content, ' html ', ' 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# defining the sweep port function , the default port is 1-65535def scan1 (ip,port= ' 1-65535 '):   nm = nmap. Portscanner ()   nm.scan (Ip,port)   global result  result = result  +  "


This article is from the "Smoke Free Hand" blog, please be sure to keep this source http://lidefu.blog.51cto.com/3429777/1719468

Python port scan

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.