Python port Scan (full connection, no multi-threaded)

Source: Internet
Author: User
‘‘‘这是一个端口全连接扫描的脚本,扫描结果会比较准确,但是比较费时间‘‘‘‘‘‘运行环境 Python3 ‘‘‘from socket import *def portScanner(host,port): try: s = socket(AF_INET,SOCK_STREAM) #注意参数 s.connect((host,port)) #注意括号 (host,port) print(‘[+] %d open‘ % port) s.close() except: #如果端口连接失败,则输出$port close print(‘[-] %d close‘ % port)def main(): setdefaulttimeout(1) ports = [20, 22, 23, 80, 111, 3306] #定义要扫描的端口,也可以在下面定义 for p in range(1,1024): for p in ports: portScanner(‘192.168.60.130‘,p) #设置要扫描的主机为192.168.60.130if __name__ == ‘__main__‘: #“Make a script both importable and executable” main() # 如果这文件中的代码被外部的python文件调用是不会被执行的

PS: For explanations in Python, if __name__ == ‘__main__‘ refer to: https://www.cnblogs.com/kex1n/p/5975575.html

Python port Scan (full connection, no multi-threaded)

Related Article

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.